Skip to content

Commit

Permalink
misc: rework definitions that enable debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
elagil authored and dragonmux committed Nov 29, 2023
1 parent 8a87a66 commit 39a8020
Show file tree
Hide file tree
Showing 26 changed files with 57 additions and 46 deletions.
8 changes: 7 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ ifeq (filter, macosx darwin, $(SYS))
CFLAGS += -Wmaybe-uninitialized -Wstringop-overflow -Wunsafe-loop-optimizations
endif

ifeq ($(PROBE_HOST),hosted)
ENABLE_DEBUG = 1
endif

ifeq ($(ENABLE_DEBUG), 1)
CFLAGS += -DENABLE_DEBUG
CFLAGS += -DENABLE_DEBUG=1
else
CFLAGS += -DENABLE_DEBUG=0
endif

SRC = \
Expand Down
2 changes: 1 addition & 1 deletion src/crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool generic_crc32(target_s *const target, uint32_t *const result, const uint32_
uint8_t bytes[128U];
#endif

#if defined(ENABLE_DEBUG)
#if ENABLE_DEBUG == 1
const uint32_t start_time = platform_time_ms();
#endif
uint32_t last_time = platform_time_ms();
Expand Down
7 changes: 6 additions & 1 deletion src/include/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@
#define PRINT_NOOP(...) \
do { \
} while (false)
#if defined(ENABLE_DEBUG)

#ifndef ENABLE_DEBUG
#define ENABLE_DEBUG 0
#endif

#if ENABLE_DEBUG == 1
#define DEBUG_ERROR(...) PLATFORM_PRINTF(__VA_ARGS__)
#define DEBUG_WARN(...) PLATFORM_PRINTF(__VA_ARGS__)
#define DEBUG_INFO(...) PLATFORM_PRINTF(__VA_ARGS__)
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/common/aux_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void aux_serial_send(size_t len);
void aux_serial_update_receive_buffer_fullness(void);
bool aux_serial_receive_buffer_empty(void);
void aux_serial_drain_receive_buffer(void);
#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
void aux_serial_stage_debug_buffer(void);
#endif
void aux_serial_stage_receive_buffer(void);
Expand Down
16 changes: 8 additions & 8 deletions src/platforms/common/usb_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*
*/

#ifndef ENABLE_DEBUG
#if ENABLE_DEBUG != 1
#include <sys/stat.h>
#include <string.h>

Expand Down Expand Up @@ -77,7 +77,7 @@ static void debug_serial_receive_callback(usbd_device *dev, uint8_t ep);
static bool debug_serial_send_complete = true;
#endif

#if defined(ENABLE_DEBUG) && defined(PLATFORM_HAS_DEBUG)
#if (ENABLE_DEBUG == 1) && defined(PLATFORM_HAS_DEBUG)
/*
* This call initialises "SemiHosting", only we then do our own SVC interrupt things to
* route all output through to the debug USB serial interface if debug_bmp is true.
Expand Down Expand Up @@ -214,7 +214,7 @@ void usb_serial_set_config(usbd_device *dev, uint16_t value)
usb_serial_set_state(dev, GDB_IF_NO, CDCACM_GDB_ENDPOINT + 1U);
usb_serial_set_state(dev, UART_IF_NO, CDCACM_UART_ENDPOINT + 1U);

#if defined(ENABLE_DEBUG) && defined(PLATFORM_HAS_DEBUG)
#if (ENABLE_DEBUG == 1) && defined(PLATFORM_HAS_DEBUG)
initialise_monitor_handles();
#endif
}
Expand Down Expand Up @@ -249,7 +249,7 @@ uint32_t debug_serial_fifo_send(const char *const fifo, const uint32_t fifo_begi
return fifo_begin;
}

#if defined(ENABLE_DEBUG) && defined(PLATFORM_HAS_DEBUG)
#if (ENABLE_DEBUG == 1) && defined(PLATFORM_HAS_DEBUG)
static bool debug_serial_fifo_buffer_empty(void)
{
return debug_serial_debug_write_index == debug_serial_debug_read_index;
Expand All @@ -270,17 +270,17 @@ static void debug_serial_send_data(void)
* If fifo empty, nothing further to do. */
if (usb_get_config() != 1 ||
(aux_serial_receive_buffer_empty()
#if defined(ENABLE_DEBUG) && defined(PLATFORM_HAS_DEBUG)
#if (ENABLE_DEBUG == 1) && defined(PLATFORM_HAS_DEBUG)
&& debug_serial_fifo_buffer_empty()
#endif
)) {
#if defined(ENABLE_DEBUG) && defined(PLATFORM_HAS_DEBUG)
#if (ENABLE_DEBUG == 1) && defined(PLATFORM_HAS_DEBUG)
debug_serial_debug_read_index = debug_serial_debug_write_index;
#endif
aux_serial_drain_receive_buffer();
debug_serial_send_complete = true;
} else {
#if defined(ENABLE_DEBUG) && defined(PLATFORM_HAS_DEBUG)
#if (ENABLE_DEBUG == 1) && defined(PLATFORM_HAS_DEBUG)
debug_serial_debug_read_index = debug_serial_fifo_send(
debug_serial_debug_buffer, debug_serial_debug_read_index, debug_serial_debug_write_index);
#endif
Expand Down Expand Up @@ -339,7 +339,7 @@ static void debug_serial_receive_callback(usbd_device *dev, uint8_t ep)
#endif
}

#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
#ifdef PLATFORM_HAS_DEBUG
static void debug_serial_append_char(const char c)
{
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/f072/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
#define TRACE_IRQ NVIC_TIM3_IRQ
#define TRACE_ISR tim3_isr

#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
extern bool debug_bmp;
#define DEBUG printf
#else
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/f3/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
#define TRACE_IRQ NVIC_TIM3_IRQ
#define TRACE_ISR tim3_isr

#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
extern bool debug_bmp;
#define DEBUG printf
#else
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/hosted/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ifeq ($(origin CC),default)
CC := gcc
endif
SYS := $(shell $(CC) -dumpmachine)
CFLAGS += -DENABLE_DEBUG -DPLATFORM_HAS_DEBUG
CFLAGS += -DPLATFORM_HAS_DEBUG
CFLAGS +=-I ./target

ENABLE_CORTEXAR := 1
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/hosted/dap_jtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static void dap_jtag_tdi_seq(const bool final_tms, const uint8_t *const data_in,

static bool dap_jtag_next(const bool tms, const bool tdi)
{
#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
const uint8_t tms_byte = tms ? 1 : 0;
#endif
const uint8_t tdi_byte = tdi ? 1 : 0;
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/native/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define PLATFORM_HAS_TRACESWO
#define PLATFORM_HAS_POWER_SWITCH

#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
#define PLATFORM_HAS_DEBUG
extern bool debug_bmp;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/stlink/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <libopencm3/stm32/memorymap.h>
#include <libopencm3/usb/usbd.h>

#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
#define PLATFORM_HAS_DEBUG
extern bool debug_bmp;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/stlinkv3/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <libopencm3/stm32/f1/memorymap.h>
#include <libopencm3/usb/usbd.h>

#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
#define PLATFORM_HAS_DEBUG
extern bool debug_bmp;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/swlink/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "timing.h"
#include "timing_stm32.h"

#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
#define PLATFORM_HAS_DEBUG
extern bool debug_bmp;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ static void remote_packet_process_general(char *packet, const size_t packet_len)
#endif
break;
case REMOTE_START:
#if defined(ENABLE_DEBUG) && defined(PLATFORM_HAS_DEBUG)
#if (ENABLE_DEBUG == 1) && defined(PLATFORM_HAS_DEBUG)
debug_bmp = true;
#endif
remote_respond_string(REMOTE_RESP_OK, PLATFORM_IDENT "" FIRMWARE_VERSION);
Expand Down
12 changes: 6 additions & 6 deletions src/target/adiv5.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ typedef enum arm_arch {
aa_end
} arm_arch_e;

#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
#define ARM_COMPONENT_STR(...) __VA_ARGS__
#else
#define ARM_COMPONENT_STR(...)
Expand Down Expand Up @@ -177,7 +177,7 @@ static const struct {
uint16_t arch_id;
arm_arch_e arch;
cid_class_e cidc;
#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
const char *type;
const char *full;
#endif
Expand Down Expand Up @@ -272,7 +272,7 @@ static const struct {
{0xfff, 0x00, 0, aa_end, cidc_unknown, ARM_COMPONENT_STR("end", "end")},
};

#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
static const char *adiv5_arm_ap_type_string(const uint8_t ap_type, const uint8_t ap_class)
{
/*
Expand Down Expand Up @@ -543,7 +543,7 @@ static void adiv5_component_probe(
return;
}

#if defined(ENABLE_DEBUG)
#if ENABLE_DEBUG == 1
char *indent = alloca(recursion + 1U);

for (size_t i = 0; i < recursion; i++)
Expand Down Expand Up @@ -608,7 +608,7 @@ static void adiv5_component_probe(
}
}

#if defined(ENABLE_DEBUG) && defined(PLATFORM_HAS_DEBUG)
#if (ENABLE_DEBUG == 1) && defined(PLATFORM_HAS_DEBUG)
/* Check SYSMEM bit */
const uint32_t memtype = adiv5_mem_read32(ap, addr | ADIV5_ROM_MEMTYPE) & ADIV5_ROM_MEMTYPE_SYSMEM;

Expand Down Expand Up @@ -747,7 +747,7 @@ adiv5_access_port_s *adiv5_new_ap(adiv5_debug_port_s *dp, uint8_t apsel)

memcpy(ap, &tmpap, sizeof(*ap));

#if defined(ENABLE_DEBUG)
#if ENABLE_DEBUG == 1
/* Grab the config register to get a complete set */
uint32_t cfg = adiv5_ap_read(ap, ADIV5_AP_CFG);
DEBUG_INFO("AP %3u: IDR=%08" PRIx32 " CFG=%08" PRIx32 " BASE=%08" PRIx32 " CSW=%08" PRIx32, apsel, ap->idr, cfg,
Expand Down
2 changes: 1 addition & 1 deletion src/target/cortexar.c
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ static void cortexr_mem_handle_fault(
const cortexar_priv_s *const priv = (cortexar_priv_s *)target->priv;
/* If we suffered a fault of some kind, grab the reason and restore DFSR/DFAR */
if (priv->core_status & CORTEXAR_STATUS_DATA_FAULT) {
#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
const uint32_t fault_status = cortexar_coproc_read(target, CORTEXAR_DFSR);
const uint32_t fault_addr = cortexar_coproc_read(target, CORTEXAR_DFAR);
#else
Expand Down
4 changes: 2 additions & 2 deletions src/target/cortexm.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ typedef struct cortexm_priv {
uint32_t demcr;
} cortexm_priv_s;

#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
const char *const semihosting_names[] = {
"",
"SYS_OPEN",
Expand Down Expand Up @@ -1470,7 +1470,7 @@ static int cortexm_hostio_request(target_s *target)
target_mem_read(target, params, arm_regs[1], sizeof(params));
int32_t ret = 0;

#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
const char *syscall_descr = NULL;
if (syscall < ARRAY_LENGTH(semihosting_names))
syscall_descr = semihosting_names[syscall];
Expand Down
2 changes: 1 addition & 1 deletion src/target/efm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ static bool efm32_flash_write(target_flash_s *f, target_addr_t dest, const void
/* Run flashloader */
const bool ret = cortexm_run_stub(t, SRAM_BASE, dest, STUB_BUFFER_BASE, len, priv_storage->device->msc_addr) == 0;

#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
/* Check the MSC_IF */
uint32_t msc = priv_storage->device->msc_addr;
uint32_t msc_if = target_mem_read32(t, EFM32_MSC_IF(msc));
Expand Down
4 changes: 2 additions & 2 deletions src/target/imxrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ bool imxrt_probe(target_s *const target)
snprintf(priv->name, IMXRT_NAME_MAX_LENGTH, "i.MXRT%u", priv->chip_id);
target->driver = priv->name;

#if defined(ENABLE_DEBUG) && (PC_HOSTED == 1 || defined(ESP_LOGD))
#if (ENABLE_DEBUG == 1) && (PC_HOSTED == 1 || defined(ESP_LOGD))
const uint8_t boot_mode = (target_mem_read32(target, IMXRT_SRC_BOOT_MODE2) >> 24U) & 3U;
#endif
DEBUG_TARGET("i.MXRT boot mode is %x\n", boot_mode);
Expand Down Expand Up @@ -521,7 +521,7 @@ static void imxrt_spi_wait_complete(target_s *const target)
target_mem_write32(target, IMXRT_FLEXSPI1_INT(priv), IMXRT_FLEXSPI1_INT_PRG_CMD_DONE);
/* Check if any errors occured */
if (target_mem_read32(target, IMXRT_FLEXSPI1_INT(priv)) & IMXRT_FLEXSPI1_INT_CMD_ERR) {
#if defined(ENABLE_DEBUG) && PC_HOSTED == 1
#if (ENABLE_DEBUG == 1) && PC_HOSTED == 1
/* Read out the status code and display it */
const uint32_t status = target_mem_read32(target, IMXRT_FLEXSPI1_STAT1(priv));
DEBUG_TARGET("Error executing sequence, offset %u, error code %u\n", (uint8_t)(status >> 16U) & 0xfU,
Expand Down
12 changes: 6 additions & 6 deletions src/target/jtag_devs.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ const jtag_dev_descr_s dev_descr[] = {
{
.idcode = 0x0ba00477U,
.idmask = 0x0fff0fffU,
#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
.descr = "ADIv5 JTAG-DP port.",
#endif
.handler = adiv5_jtag_dp_handler,
},
#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
{
.idcode = 0x00000477U,
.idmask = 0x00000fffU,
Expand Down Expand Up @@ -339,7 +339,7 @@ const jtag_dev_descr_s dev_descr[] = {
{
.idcode = 0x00000093U,
.idmask = 0x00000fffU,
#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
.descr = "Xilinx.",
#endif
.ir_quirks =
Expand All @@ -352,13 +352,13 @@ const jtag_dev_descr_s dev_descr[] = {
{
.idcode = 0x0000563dU,
.idmask = 0x0fffffffU,
#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
.descr = "RISC-V debug v0.13.",
#endif
.handler = riscv_jtag_dtm_handler,
},
#endif
#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
{
.idcode = 0x000007a3U,
.idmask = 0x00000fffU,
Expand Down Expand Up @@ -394,7 +394,7 @@ const jtag_dev_descr_s dev_descr[] = {
{
.idcode = 0U,
.idmask = 0U,
#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
.descr = "Unknown",
#endif
},
Expand Down
2 changes: 1 addition & 1 deletion src/target/jtag_devs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef struct jtag_ir_quirks {
typedef struct jtag_dev_descr {
uint32_t idcode;
uint32_t idmask;
#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG == 1
const char *descr;
#endif
void (*handler)(uint8_t jd_index);
Expand Down
2 changes: 1 addition & 1 deletion src/target/jtag_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static bool jtag_read_idcodes(void)

static void jtag_display_idcodes(void)
{
#if ENABLE_DEBUG
#if ENABLE_DEBUG == 1
for (size_t device = 0; device < jtag_dev_count; ++device) {
const char *description = "Unknown";
for (size_t idx = 0; dev_descr[idx].idcode; ++idx) {
Expand Down
4 changes: 2 additions & 2 deletions src/target/lpc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ typedef struct __attribute__((aligned(4))) iap_frame {
iap_result_s result;
} iap_frame_s;

#if defined(ENABLE_DEBUG)
#if ENABLE_DEBUG == 1
static const char *const iap_error[] = {
"CMD_SUCCESS",
"Invalid command",
Expand Down Expand Up @@ -261,7 +261,7 @@ iap_status_e lpc_iap_call(lpc_flash_s *const flash, iap_result_s *const result,
*result = results;

/* This guard block deals with the fact iap_error is only defined when ENABLE_DEBUG is */
#if defined(ENABLE_DEBUG)
#if ENABLE_DEBUG == 1
if (results.return_code < ARRAY_LENGTH(iap_error))
DEBUG_INFO("%s: result %s, ", __func__, iap_error[results.return_code]);
else
Expand Down
2 changes: 1 addition & 1 deletion src/target/rp.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ bool rp_probe(target_s *target)
return false;
}

#if defined(ENABLE_DEBUG)
#if ENABLE_DEBUG == 1
if ((boot_magic >> BOOTROM_VERSION_SHIFT) == 1)
DEBUG_WARN("Old Bootrom Version 1!\n");
#endif
Expand Down
Loading

0 comments on commit 39a8020

Please sign in to comment.