Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: warning shadow #1594

Merged
merged 9 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ bool debug_bmp;
#endif
unsigned cortexm_wait_timeout = 2000; /* Timeout to wait for Cortex to react on halt command. */

int command_process(target_s *t, char *cmd)
int command_process(target_s *const t, char *const cmd_buffer)
{
/* Initial estimate for argc */
size_t argc = 1;
for (size_t i = 0; i < strlen(cmd); ++i) {
if (cmd[i] == ' ' || cmd[i] == '\t')
for (size_t i = 0; i < strlen(cmd_buffer); ++i) {
if (cmd_buffer[i] == ' ' || cmd_buffer[i] == '\t')
++argc;
}

Expand All @@ -142,11 +142,11 @@ int command_process(target_s *t, char *cmd)
*/
const char **const argv = alloca(sizeof(const char *) * argc);

/* Tokenize cmd to find argv */
/* Tokenize cmd_buffer to find argv */
argc = 0;
/* Reentrant strtok needs a state pointer to the unprocessed part */
char *token_state = NULL;
for (const char *part = strtok_r(cmd, " \t", &token_state); part; part = strtok_r(NULL, " \t", &token_state))
for (const char *part = strtok_r(cmd_buffer, " \t", &token_state); part; part = strtok_r(NULL, " \t", &token_state))
argv[argc++] = part;

/* Look for match and call handler */
Expand Down
6 changes: 3 additions & 3 deletions src/gdb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ static void exec_q_rcmd(const char *packet, const size_t length)
gdb_putpacketz("OK");
else {
const char *const response = "Failed\n";
const size_t length = strlen(response);
char pbuf[length * 2 + 1];
gdb_putpacket(hexify(pbuf, response, length), 2 * length);
const size_t response_length = strlen(response);
char pbuf[response_length * 2 + 1];
gdb_putpacket(hexify(pbuf, response, response_length), 2 * response_length);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/include/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "target.h"

int command_process(target_s *t, char *cmd);
int command_process(target_s *t, char *cmd_buffer);

/*
* Attempts to parse a string as either being "enable" or "disable".
Expand Down
14 changes: 7 additions & 7 deletions src/platforms/hosted/bmp_hosted.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ typedef struct usb_link {
} usb_link_s;
#endif

typedef struct bmp_info {
bmp_type_t bmp_type;
typedef struct bmda_probe {
probe_type_e type;
char dev;
char serial[64];
char manufacturer[512];
Expand All @@ -89,14 +89,14 @@ typedef struct bmp_info {
uint8_t in_ep;
uint8_t out_ep;
#endif
} bmp_info_s;
} bmda_probe_s;

typedef struct timeval timeval_s;

extern bmp_info_s info;
void bmp_ident(bmp_info_s *info);
int find_debuggers(bmda_cli_options_s *cl_opts, bmp_info_s *info);
void libusb_exit_function(bmp_info_s *info);
extern bmda_probe_s bmda_probe_info;
void bmp_ident(bmda_probe_s *info);
int find_debuggers(bmda_cli_options_s *cl_opts, bmda_probe_s *info);
void libusb_exit_function(bmda_probe_s *info);

#if HOSTED_BMP_ONLY == 1
bool device_is_bmp_gdb_port(const char *device);
Expand Down
56 changes: 28 additions & 28 deletions src/platforms/hosted/bmp_libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,31 @@ void stlinkv2_read_serial(libusb_device_descriptor_s *device_descriptor, libusb_
typedef struct debugger_device {
uint16_t vendor;
uint16_t product;
bmp_type_t type;
probe_type_e type;
void (*function)(
libusb_device_descriptor_s *, libusb_device *, libusb_device_handle *, char **, char **, char **, char **);
char *type_string;
} debugger_device_s;

/* Create the list of debuggers BMDA works with */
static const debugger_device_s debugger_devices[] = {
{VENDOR_ID_BMP, PRODUCT_ID_BMP, BMP_TYPE_BMP, bmp_read_product_version, "Black Magic Probe"},
{VENDOR_ID_STLINK, PRODUCT_ID_STLINKV2, BMP_TYPE_STLINK_V2, stlinkv2_read_serial, "ST-Link v2"},
{VENDOR_ID_STLINK, PRODUCT_ID_STLINKV21, BMP_TYPE_STLINK_V2, NULL, "ST-Link v2.1"},
{VENDOR_ID_STLINK, PRODUCT_ID_STLINKV21_MSD, BMP_TYPE_STLINK_V2, NULL, "ST-Link v2.1 MSD"},
{VENDOR_ID_STLINK, PRODUCT_ID_STLINKV3_NO_MSD, BMP_TYPE_STLINK_V2, NULL, "ST-Link v2.1 No MSD"},
{VENDOR_ID_STLINK, PRODUCT_ID_STLINKV3, BMP_TYPE_STLINK_V2, NULL, "ST-Link v3"},
{VENDOR_ID_STLINK, PRODUCT_ID_STLINKV3E, BMP_TYPE_STLINK_V2, NULL, "ST-Link v3E"},
{VENDOR_ID_SEGGER, PRODUCT_ID_ANY, BMP_TYPE_JLINK, NULL, "Segger JLink"},
{VENDOR_ID_FTDI, PRODUCT_ID_FTDI_FT2232, BMP_TYPE_FTDI, NULL, "FTDI FT2232"},
{VENDOR_ID_FTDI, PRODUCT_ID_FTDI_FT4232, BMP_TYPE_FTDI, NULL, "FTDI FT4232"},
{VENDOR_ID_FTDI, PRODUCT_ID_FTDI_FT232, BMP_TYPE_FTDI, NULL, "FTDI FT232"},
{0, 0, BMP_TYPE_NONE, NULL, ""},
{VENDOR_ID_BMP, PRODUCT_ID_BMP, PROBE_TYPE_BMP, bmp_read_product_version, "Black Magic Probe"},
{VENDOR_ID_STLINK, PRODUCT_ID_STLINKV2, PROBE_TYPE_STLINK_V2, stlinkv2_read_serial, "ST-Link v2"},
{VENDOR_ID_STLINK, PRODUCT_ID_STLINKV21, PROBE_TYPE_STLINK_V2, NULL, "ST-Link v2.1"},
{VENDOR_ID_STLINK, PRODUCT_ID_STLINKV21_MSD, PROBE_TYPE_STLINK_V2, NULL, "ST-Link v2.1 MSD"},
{VENDOR_ID_STLINK, PRODUCT_ID_STLINKV3_NO_MSD, PROBE_TYPE_STLINK_V2, NULL, "ST-Link v2.1 No MSD"},
{VENDOR_ID_STLINK, PRODUCT_ID_STLINKV3, PROBE_TYPE_STLINK_V2, NULL, "ST-Link v3"},
{VENDOR_ID_STLINK, PRODUCT_ID_STLINKV3E, PROBE_TYPE_STLINK_V2, NULL, "ST-Link v3E"},
{VENDOR_ID_SEGGER, PRODUCT_ID_ANY, PROBE_TYPE_JLINK, NULL, "Segger JLink"},
{VENDOR_ID_FTDI, PRODUCT_ID_FTDI_FT2232, PROBE_TYPE_FTDI, NULL, "FTDI FT2232"},
{VENDOR_ID_FTDI, PRODUCT_ID_FTDI_FT4232, PROBE_TYPE_FTDI, NULL, "FTDI FT4232"},
{VENDOR_ID_FTDI, PRODUCT_ID_FTDI_FT232, PROBE_TYPE_FTDI, NULL, "FTDI FT232"},
{0, 0, PROBE_TYPE_NONE, NULL, ""},
};

const debugger_device_s *get_debugger_device_from_vid_pid(const uint16_t probe_vid, const uint16_t probe_pid)
{
/* Iterate over the list excluding the last entry (BMP_TYPE_NONE) */
/* Iterate over the list excluding the last entry (PROBE_TYPE_NONE) */
for (size_t index = 0; index < ARRAY_LENGTH(debugger_devices) - 1U; index++) {
/* Check for a vendor id match */
if (debugger_devices[index].vendor != probe_vid)
Expand All @@ -92,11 +92,11 @@ const debugger_device_s *get_debugger_device_from_vid_pid(const uint16_t probe_v
if (debugger_devices[index].product == PRODUCT_ID_ANY || probe_pid == debugger_devices[index].product)
return &debugger_devices[index];
}
/* Return the last entry in the list (BMP_TYPE_NONE) */
/* Return the last entry in the list (PROBE_TYPE_NONE) */
return &debugger_devices[ARRAY_LENGTH(debugger_devices) - 1U];
}

void bmp_ident(bmp_info_s *info)
void bmp_ident(bmda_probe_s *info)
{
DEBUG_INFO("Black Magic Debug App " FIRMWARE_VERSION "\n for Black Magic Probe, ST-Link v2 and v3, CMSIS-DAP, "
"J-Link and FTDI (MPSSE)\n");
Expand All @@ -106,7 +106,7 @@ void bmp_ident(bmp_info_s *info)
}
}

void libusb_exit_function(bmp_info_s *info)
void libusb_exit_function(bmda_probe_s *info)
{
if (!info->usb_link)
return;
Expand Down Expand Up @@ -260,7 +260,7 @@ static probe_info_s *process_ftdi_probe(void)
if (add_probe) {
const char *const manufacturer = strdup("FTDI");
probe_list = probe_info_add_by_id(
probe_list, BMP_TYPE_FTDI, NULL, vid, pid, manufacturer, product, serial, strdup("---"));
probe_list, PROBE_TYPE_FTDI, NULL, vid, pid, manufacturer, product, serial, strdup("---"));
} else {
free(serial);
free(product);
Expand Down Expand Up @@ -325,12 +325,12 @@ static void process_cmsis_interface(const libusb_device_descriptor_s *const devi
else
product = get_device_descriptor_string(handle, device_descriptor->iProduct);

*probe_list = probe_info_add_by_id(*probe_list, BMP_TYPE_CMSIS_DAP, device, device_descriptor->idVendor,
*probe_list = probe_info_add_by_id(*probe_list, PROBE_TYPE_CMSIS_DAP, device, device_descriptor->idVendor,
device_descriptor->idProduct, manufacturer, product, serial, version);
}

static bool process_cmsis_interface_probe(
libusb_device_descriptor_s *device_descriptor, libusb_device *device, probe_info_s **probe_list, bmp_info_s *info)
libusb_device_descriptor_s *device_descriptor, libusb_device *device, probe_info_s **probe_list, bmda_probe_s *info)
{
(void)info;
/* Try to get the active configuration descriptor for the device */
Expand Down Expand Up @@ -374,7 +374,7 @@ static bool process_cmsis_interface_probe(
return cmsis_dap;
}

static void check_cmsis_interface_type(libusb_device *const device, bmp_info_s *const info)
static void check_cmsis_interface_type(libusb_device *const device, bmda_probe_s *const info)
{
/* Try to get the active configuration descriptor for the device */
libusb_config_descriptor_s *config;
Expand Down Expand Up @@ -430,7 +430,7 @@ static bool process_vid_pid_table_probe(
/* Check for a match */
const debugger_device_s *const debugger_device =
get_debugger_device_from_vid_pid(device_descriptor->idVendor, device_descriptor->idProduct);
if (debugger_device->type == BMP_TYPE_NONE)
if (debugger_device->type == PROBE_TYPE_NONE)
return false;

libusb_device_handle *handle = NULL;
Expand Down Expand Up @@ -468,7 +468,7 @@ static bool process_vid_pid_table_probe(
return true;
}

static const probe_info_s *scan_for_devices(bmp_info_s *info)
static const probe_info_s *scan_for_devices(bmda_probe_s *info)
{
/*
* If we are running on Windows the proprietary FTD2XX library is used
Expand Down Expand Up @@ -504,7 +504,7 @@ static const probe_info_s *scan_for_devices(bmp_info_s *info)
return probe_info_correct_order(probe_list);
}

int find_debuggers(bmda_cli_options_s *cl_opts, bmp_info_s *info)
int find_debuggers(bmda_cli_options_s *cl_opts, bmda_probe_s *info)
{
if (cl_opts->opt_device)
return 1;
Expand Down Expand Up @@ -542,17 +542,17 @@ int find_debuggers(bmda_cli_options_s *cl_opts, bmp_info_s *info)
return cl_opts->opt_list_only ? 0 : 1; // false;
}

/* We found a matching probe, populate bmp_info_s and signal success */
probe_info_to_bmp_info(probe, info);
/* We found a matching probe, populate bmda_probe_s and signal success */
probe_info_to_bmda_probe(probe, info);
/* If the selected probe is an FTDI adapter try to resolve the adaptor type */
if (probe->type == BMP_TYPE_FTDI && !ftdi_lookup_adaptor_descriptor(cl_opts, probe)) {
if (probe->type == PROBE_TYPE_FTDI && !ftdi_lookup_adaptor_descriptor(cl_opts, probe)) {
// Don't know the cable type, ask user to specify with "-c"
DEBUG_WARN("Multiple FTDI adapters match Vendor and Product ID.\n");
DEBUG_WARN("Please specify adapter type on command line using \"-c\" option.\n");
return -1; //false
}
/* If the selected probe is CMSIS-DAP, check for v2 interfaces */
if (probe->type == BMP_TYPE_CMSIS_DAP)
if (probe->type == PROBE_TYPE_CMSIS_DAP)
check_cmsis_interface_type(probe->device, info);

probe_info_list_free(probe_list);
Expand Down
18 changes: 9 additions & 9 deletions src/platforms/hosted/bmp_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@
#include "utils.h"
#include "version.h"

void bmp_ident(bmp_info_s *info)
void bmp_ident(bmda_probe_s *info)
{
DEBUG_INFO("Black Magic Debug App (for BMP only) %s\n", FIRMWARE_VERSION);
if (!info)
return;
DEBUG_INFO("Using:\n %s %s %s\n", info->manufacturer, info->version, info->serial);
}

void libusb_exit_function(bmp_info_s *info)
void libusb_exit_function(bmda_probe_s *info)
{
(void)info;
};

#ifdef __APPLE__
int find_debuggers(bmda_cli_options_s *cl_opts, bmp_info_s *info)
int find_debuggers(bmda_cli_options_s *cl_opts, bmda_probe_s *info)
{
DEBUG_ERROR("Please implement find_debuggers for MACOS!\n");
(void)cl_opts;
Expand Down Expand Up @@ -79,7 +79,7 @@ DEFINE_DEVPROPKEY(DEVPKEY_Device_BusReportedDeviceDesc, 0x540b947e, 0x8b40, 0x45

/* List all USB devices with some additional information.
* Unfortunately, this code is quite ugly. */
int find_debuggers(bmda_cli_options_s *cl_opts, bmp_info_s *info)
int find_debuggers(bmda_cli_options_s *cl_opts, bmda_probe_s *info)
{
unsigned i;
DWORD dwSize;
Expand All @@ -92,7 +92,7 @@ int find_debuggers(bmda_cli_options_s *cl_opts, bmp_info_s *info)
size_t probes_found = 0;
bool is_printing_probes_info = cl_opts->opt_list_only != 0;

info->bmp_type = BMP_TYPE_BMP;
info->type = PROBE_TYPE_BMP;

hDevInfo = SetupDiGetClassDevs(0, "USB", NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);
if (hDevInfo == INVALID_HANDLE_VALUE)
Expand Down Expand Up @@ -291,7 +291,7 @@ static probe_info_s *parse_device_node(const char *name, probe_info_s *probe_lis
return probe_list;
}

return probe_info_add_by_serial(probe_list, BMP_TYPE_BMP, type, product, serial, version);
return probe_info_add_by_serial(probe_list, PROBE_TYPE_BMP, type, product, serial, version);
}

static const probe_info_s *scan_for_devices(void)
Expand Down Expand Up @@ -322,7 +322,7 @@ static const probe_info_s *scan_for_devices(void)
return probe_info_correct_order(probe_list);
}

int find_debuggers(bmda_cli_options_s *cl_opts, bmp_info_s *info)
int find_debuggers(bmda_cli_options_s *cl_opts, bmda_probe_s *info)
{
if (cl_opts->opt_device)
return 1;
Expand Down Expand Up @@ -352,8 +352,8 @@ int find_debuggers(bmda_cli_options_s *cl_opts, bmp_info_s *info)
return 1; // false;
}

/* We found a matching probe, populate bmp_info_s and signal success */
probe_info_to_bmp_info(probe, info);
/* We found a matching probe, populate bmda_probe_s and signal success */
probe_info_to_bmda_probe(probe, info);
probe_info_list_free(probe_list);
return 0; // true;
}
Expand Down
Loading