From d8d1feb424fe57e54485212698f53fb90edbdf35 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 13 Jan 2021 14:32:39 -0500 Subject: [PATCH] gdb: convert arc to new-style debug macros Add the standard arc_debug_printf, but also arc_linux_debug_printf, arc_linux_nat_debug_printf and arc_newlib_debug_printf to match the prefixes currently used in the debug messages. gdb/ChangeLog: * arc-tdep.h (arc_debug_printf): New. * arc-tdep.c: Use arc_debug_printf. * arc-linux-nat.c (arc_linux_nat_debug_printf): Add and use. * arc-linux-tdep.c (arc_linux_debug_printf): Add and use. * arc-newlib-tdep.c (arc_newlib_debug_printf): Add and use. Change-Id: I5d937566ed7a1925f7982e8809802c8f0560d8c6 --- gdb/ChangeLog | 8 +++ gdb/arc-linux-nat.c | 16 ++--- gdb/arc-linux-tdep.c | 43 ++++++-------- gdb/arc-newlib-tdep.c | 11 ++-- gdb/arc-tdep.c | 135 ++++++++++++++++-------------------------- gdb/arc-tdep.h | 5 ++ 6 files changed, 98 insertions(+), 120 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8b40c5a232c..23f6356ceef 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2021-01-13 Simon Marchi + + * arc-tdep.h (arc_debug_printf): New. + * arc-tdep.c: Use arc_debug_printf. + * arc-linux-nat.c (arc_linux_nat_debug_printf): Add and use. + * arc-linux-tdep.c (arc_linux_debug_printf): Add and use. + * arc-newlib-tdep.c (arc_newlib_debug_printf): Add and use. + 2021-01-13 Simon Marchi * arc-tdep.h (arc_debug): Change type to bool. diff --git a/gdb/arc-linux-nat.c b/gdb/arc-linux-nat.c index b03363a4865..642f3a769bd 100644 --- a/gdb/arc-linux-nat.c +++ b/gdb/arc-linux-nat.c @@ -46,6 +46,11 @@ /* Defines ps_err_e, struct ps_prochandle. */ #include "gdb_proc_service.h" +/* Print an "arc-linux-nat" debug statement. */ + +#define arc_linux_nat_debug_printf(fmt, ...) \ + debug_prefixed_printf_cond (arc_debug, "arc-linux-nat", fmt, ##__VA_ARGS__) + /* Linux starting with 4.12 supports NT_ARC_V2 note type, which adds R30, R58 and R59 registers, which are specific to ARC HS and aren't available in ARC 700. */ @@ -219,9 +224,7 @@ void fill_fpregset (const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regnum) { - if (arc_debug) - debug_printf ("arc-linux-nat: fill_fpregset called."); - return; + arc_linux_nat_debug_printf ("called"); } /* ARC doesn't have separate FP registers. This function is exported @@ -230,9 +233,7 @@ fill_fpregset (const struct regcache *regcache, void supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp) { - if (arc_debug) - debug_printf ("arc-linux-nat: supply_fpregset called."); - return; + arc_linux_nat_debug_printf ("called"); } /* Implement the "read_description" method of linux_nat_target. */ @@ -295,8 +296,7 @@ ps_err_e ps_get_thread_area (struct ps_prochandle *ph, lwpid_t lwpid, int idx, void **base) { - if (arc_debug) - debug_printf ("arc-linux-nat: ps_get_thread_area called"); + arc_linux_nat_debug_printf ("called"); if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0) return PS_ERR; diff --git a/gdb/arc-linux-tdep.c b/gdb/arc-linux-tdep.c index f29279d8fba..f41cb203358 100644 --- a/gdb/arc-linux-tdep.c +++ b/gdb/arc-linux-tdep.c @@ -31,6 +31,11 @@ #include "arc-tdep.h" #include "arch/arc.h" +/* Print an "arc-linux" debug statement. */ + +#define arc_linux_debug_printf(fmt, ...) \ + debug_prefixed_printf_cond (arc_debug, "arc-linux", fmt, ##__VA_ARGS__) + #define REGOFF(offset) (offset * ARC_REGISTER_SIZE) /* arc_linux_sc_reg_offsets[i] is the offset of register i in the `struct @@ -158,11 +163,7 @@ arc_linux_is_sigtramp (struct frame_info *this_frame) struct gdbarch *gdbarch = get_frame_arch (this_frame); CORE_ADDR pc = get_frame_pc (this_frame); - if (arc_debug) - { - debug_printf ("arc-linux: arc_linux_is_sigtramp, pc=%s\n", - paddress(gdbarch, pc)); - } + arc_linux_debug_printf ("pc=%s", paddress(gdbarch, pc)); static const gdb_byte insns_be_hs[] = { 0x20, 0x8a, 0x12, 0xc2, /* mov r8,nr_rt_sigreturn */ @@ -383,15 +384,12 @@ arc_linux_software_single_step (struct regcache *regcache) regcache_cooked_read_unsigned (regcache, ARC_LP_COUNT_REGNUM, &lp_count); - if (arc_debug) - { - debug_printf ("arc-linux: lp_start = %s, lp_end = %s, " - "lp_count = %s, next_pc = %s\n", - paddress (gdbarch, lp_start), - paddress (gdbarch, lp_end), - pulongest (lp_count), - paddress (gdbarch, next_pc)); - } + arc_linux_debug_printf ("lp_start = %s, lp_end = %s, " + "lp_count = %s, next_pc = %s", + paddress (gdbarch, lp_start), + paddress (gdbarch, lp_end), + pulongest (lp_count), + paddress (gdbarch, next_pc)); if (next_pc == lp_end && lp_count > 1) { @@ -436,17 +434,13 @@ arc_linux_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc) if (resolver.minsym != nullptr) { CORE_ADDR res_addr = BMSYMBOL_VALUE_ADDRESS (resolver); - debug_printf ("arc-linux: skip_solib_resolver (): " - "pc = %s, resolver at %s\n", - print_core_address (gdbarch, pc), - print_core_address (gdbarch, res_addr)); + arc_linux_debug_printf ("pc = %s, resolver at %s", + print_core_address (gdbarch, pc), + print_core_address (gdbarch, res_addr)); } else - { - debug_printf ("arc-linux: skip_solib_resolver (): " - "pc = %s, no resolver found\n", - print_core_address (gdbarch, pc)); - } + arc_linux_debug_printf ("pc = %s, no resolver found", + print_core_address (gdbarch, pc)); } if (resolver.minsym != nullptr && BMSYMBOL_VALUE_ADDRESS (resolver) == pc) @@ -625,8 +619,7 @@ arc_linux_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch) { struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); - if (arc_debug) - debug_printf ("arc-linux: GNU/Linux OS/ABI initialization.\n"); + arc_linux_debug_printf ("GNU/Linux OS/ABI initialization."); /* Fill in target-dependent info in ARC-private structure. */ tdep->is_sigtramp = arc_linux_is_sigtramp; diff --git a/gdb/arc-newlib-tdep.c b/gdb/arc-newlib-tdep.c index 8a83aaf6313..325e11b39a2 100644 --- a/gdb/arc-newlib-tdep.c +++ b/gdb/arc-newlib-tdep.c @@ -24,13 +24,17 @@ #include "arc-tdep.h" #include "osabi.h" +/* Print an "arc-newlib" debug statement. */ + +#define arc_newlib_debug_printf(fmt, ...) \ + debug_prefixed_printf_cond (arc_debug, "arc-newlib", fmt, ##__VA_ARGS__) + /* Implement the 'init_osabi' method of struct gdb_osabi_handler. */ static void arc_newlib_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch) { - if (arc_debug) - debug_printf ("arc-newlib: Initialization.\n"); + arc_newlib_debug_printf ("Initialization."); struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); @@ -44,8 +48,7 @@ arc_newlib_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch) static enum gdb_osabi arc_newlib_osabi_sniffer (bfd *abfd) { - if (arc_debug) - debug_printf ("arc-newlib: OS/ABI sniffer.\n"); + arc_newlib_debug_printf ("OS/ABI sniffer."); /* crt0.S in libgloss for ARC defines .ivt section for interrupt handlers. If this section is not present then this is likely not a newlib - could be diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c index e2f855142e1..8385ad79f9f 100644 --- a/gdb/arc-tdep.c +++ b/gdb/arc-tdep.c @@ -601,9 +601,8 @@ arc_write_pc (struct regcache *regcache, CORE_ADDR new_pc) { struct gdbarch *gdbarch = regcache->arch (); - if (arc_debug) - debug_printf ("arc: Writing PC, new value=%s\n", - paddress (gdbarch, new_pc)); + arc_debug_printf ("Writing PC, new value=%s", + paddress (gdbarch, new_pc)); regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), new_pc); @@ -614,13 +613,10 @@ arc_write_pc (struct regcache *regcache, CORE_ADDR new_pc) if ((status32 & ARC_STATUS32_DE_MASK) != 0) { - if (arc_debug) - { - debug_printf ("arc: Changing PC while in delay slot. Will " + arc_debug_printf ("Changing PC while in delay slot. Will " "reset STATUS32.DE bit to zero. Value of STATUS32 " - "register is 0x%s\n", + "register is 0x%s", phex (status32, ARC_REGISTER_SIZE)); - } /* Reset bit and write to the cache. */ status32 &= ~0x40; @@ -734,8 +730,7 @@ arc_push_dummy_call (struct gdbarch *gdbarch, struct value *function, function_call_return_method return_method, CORE_ADDR struct_addr) { - if (arc_debug) - debug_printf ("arc: push_dummy_call (nargs = %d)\n", nargs); + arc_debug_printf ("nargs = %d", nargs); int arg_reg = ARC_FIRST_ARG_REGNUM; @@ -751,9 +746,8 @@ arc_push_dummy_call (struct gdbarch *gdbarch, struct value *function, /* Pass the return address in the first argument register. */ regcache_cooked_write_unsigned (regcache, arg_reg, struct_addr); - if (arc_debug) - debug_printf ("arc: struct return address %s passed in R%d", - print_core_address (gdbarch, struct_addr), arg_reg); + arc_debug_printf ("struct return address %s passed in R%d", + print_core_address (gdbarch, struct_addr), arg_reg); arg_reg++; } @@ -771,8 +765,7 @@ arc_push_dummy_call (struct gdbarch *gdbarch, struct value *function, total_space += space; - if (arc_debug) - debug_printf ("arc: arg %d: %u bytes -> %u\n", i, len, space); + arc_debug_printf ("arg %d: %u bytes -> %u", i, len, space); } /* Allocate a buffer to hold a memory image of the arguments. */ @@ -786,9 +779,8 @@ arc_push_dummy_call (struct gdbarch *gdbarch, struct value *function, unsigned int space = align_up (len, 4); memcpy (data, value_contents (args[i]), (size_t) len); - if (arc_debug) - debug_printf ("arc: copying arg %d, val 0x%08x, len %d to mem\n", - i, *((int *) value_contents (args[i])), len); + arc_debug_printf ("copying arg %d, val 0x%08x, len %d to mem", + i, *((int *) value_contents (args[i])), len); data += space; } @@ -797,9 +789,8 @@ arc_push_dummy_call (struct gdbarch *gdbarch, struct value *function, data = memory_image; while (arg_reg <= ARC_LAST_ARG_REGNUM) { - if (arc_debug) - debug_printf ("arc: passing 0x%02x%02x%02x%02x in register R%d\n", - data[0], data[1], data[2], data[3], arg_reg); + arc_debug_printf ("passing 0x%02x%02x%02x%02x in register R%d", + data[0], data[1], data[2], data[3], arg_reg); /* Note we don't use write_unsigned here, since that would convert the byte order, but we are already in the correct byte order. */ @@ -819,8 +810,7 @@ arc_push_dummy_call (struct gdbarch *gdbarch, struct value *function, operation). */ if (total_space > 0) { - if (arc_debug) - debug_printf ("arc: passing %d bytes on stack\n", total_space); + arc_debug_printf ("passing %d bytes on stack\n", total_space); sp -= total_space; write_memory (sp, data, (int) total_space); @@ -916,8 +906,7 @@ arc_extract_return_value (struct gdbarch *gdbarch, struct type *type, { unsigned int len = TYPE_LENGTH (type); - if (arc_debug) - debug_printf ("arc: extract_return_value\n"); + arc_debug_printf ("called"); if (len <= ARC_REGISTER_SIZE) { @@ -928,8 +917,7 @@ arc_extract_return_value (struct gdbarch *gdbarch, struct type *type, store_unsigned_integer (valbuf, (int) len, gdbarch_byte_order (gdbarch), val); - if (arc_debug) - debug_printf ("arc: returning 0x%s\n", phex (val, ARC_REGISTER_SIZE)); + arc_debug_printf ("returning 0x%s", phex (val, ARC_REGISTER_SIZE)); } else if (len <= ARC_REGISTER_SIZE * 2) { @@ -945,10 +933,9 @@ arc_extract_return_value (struct gdbarch *gdbarch, struct type *type, (int) len - ARC_REGISTER_SIZE, gdbarch_byte_order (gdbarch), high); - if (arc_debug) - debug_printf ("arc: returning 0x%s%s\n", - phex (high, ARC_REGISTER_SIZE), - phex (low, ARC_REGISTER_SIZE)); + arc_debug_printf ("returning 0x%s%s", + phex (high, ARC_REGISTER_SIZE), + phex (low, ARC_REGISTER_SIZE)); } else error (_("arc: extract_return_value: type length %u too large"), len); @@ -970,8 +957,7 @@ arc_store_return_value (struct gdbarch *gdbarch, struct type *type, { unsigned int len = TYPE_LENGTH (type); - if (arc_debug) - debug_printf ("arc: store_return_value\n"); + arc_debug_printf ("called"); if (len <= ARC_REGISTER_SIZE) { @@ -982,8 +968,7 @@ arc_store_return_value (struct gdbarch *gdbarch, struct type *type, gdbarch_byte_order (gdbarch)); regcache_cooked_write_unsigned (regcache, ARC_R0_REGNUM, val); - if (arc_debug) - debug_printf ("arc: storing 0x%s\n", phex (val, ARC_REGISTER_SIZE)); + arc_debug_printf ("storing 0x%s", phex (val, ARC_REGISTER_SIZE)); } else if (len <= ARC_REGISTER_SIZE * 2) { @@ -999,10 +984,9 @@ arc_store_return_value (struct gdbarch *gdbarch, struct type *type, regcache_cooked_write_unsigned (regcache, ARC_R0_REGNUM, low); regcache_cooked_write_unsigned (regcache, ARC_R1_REGNUM, high); - if (arc_debug) - debug_printf ("arc: storing 0x%s%s\n", - phex (high, ARC_REGISTER_SIZE), - phex (low, ARC_REGISTER_SIZE)); + arc_debug_printf ("storing 0x%s%s", + phex (high, ARC_REGISTER_SIZE), + phex (low, ARC_REGISTER_SIZE)); } else error (_("arc_store_return_value: type length too large.")); @@ -1013,8 +997,7 @@ arc_store_return_value (struct gdbarch *gdbarch, struct type *type, static int arc_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc) { - if (arc_debug) - debug_printf ("arc: get_longjmp_target\n"); + arc_debug_printf ("called"); struct gdbarch *gdbarch = get_frame_arch (frame); struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); @@ -1046,10 +1029,9 @@ arc_return_value (struct gdbarch *gdbarch, struct value *function, || valtype->code () == TYPE_CODE_UNION || TYPE_LENGTH (valtype) > 2 * ARC_REGISTER_SIZE); - if (arc_debug) - debug_printf ("arc: return_value (readbuf = %s, writebuf = %s)\n", - host_address_to_string (readbuf), - host_address_to_string (writebuf)); + arc_debug_printf ("readbuf = %s, writebuf = %s", + host_address_to_string (readbuf), + host_address_to_string (writebuf)); if (writebuf != NULL) { @@ -1400,10 +1382,9 @@ static CORE_ADDR arc_analyze_prologue (struct gdbarch *gdbarch, const CORE_ADDR entrypoint, const CORE_ADDR limit_pc, struct arc_frame_cache *cache) { - if (arc_debug) - debug_printf ("arc: analyze_prologue (entrypoint=%s, limit_pc=%s)\n", - paddress (gdbarch, entrypoint), - paddress (gdbarch, limit_pc)); + arc_debug_printf ("entrypoint=%s, limit_pc=%s", + paddress (gdbarch, entrypoint), + paddress (gdbarch, limit_pc)); /* Prologue values. Only core registers can be stored. */ pv_t regs[ARC_LAST_CORE_REGNUM + 1]; @@ -1429,9 +1410,8 @@ arc_analyze_prologue (struct gdbarch *gdbarch, const CORE_ADDR entrypoint, if (!arc_is_in_prologue (gdbarch, insn, regs, &stack)) { /* Found an instruction that is not in the prologue. */ - if (arc_debug) - debug_printf ("arc: End of prologue reached at address %s\n", - paddress (gdbarch, insn.address)); + arc_debug_printf ("End of prologue reached at address %s", + paddress (gdbarch, insn.address)); break; } @@ -1492,8 +1472,7 @@ const static int MAX_PROLOGUE_LENGTH static CORE_ADDR arc_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) { - if (arc_debug) - debug_printf ("arc: skip_prologue\n"); + arc_debug_printf ("called"); CORE_ADDR func_addr; const char *func_name; @@ -1665,19 +1644,19 @@ static void arc_print_frame_cache (struct gdbarch *gdbarch, const char *message, struct arc_frame_cache *cache, int addresses_known) { - debug_printf ("arc: frame_info %s\n", message); - debug_printf ("arc: prev_sp = %s\n", paddress (gdbarch, cache->prev_sp)); - debug_printf ("arc: frame_base_reg = %i\n", cache->frame_base_reg); - debug_printf ("arc: frame_base_offset = %s\n", - plongest (cache->frame_base_offset)); + arc_debug_printf ("frame_info %s", message); + arc_debug_printf ("prev_sp = %s", paddress (gdbarch, cache->prev_sp)); + arc_debug_printf ("frame_base_reg = %i", cache->frame_base_reg); + arc_debug_printf ("frame_base_offset = %s", + plongest (cache->frame_base_offset)); for (int i = 0; i <= ARC_BLINK_REGNUM; i++) { if (trad_frame_addr_p (cache->saved_regs, i)) - debug_printf ("arc: saved register %s at %s %s\n", - gdbarch_register_name (gdbarch, i), - (addresses_known) ? "address" : "offset", - paddress (gdbarch, cache->saved_regs[i].addr ())); + arc_debug_printf ("saved register %s at %s %s", + gdbarch_register_name (gdbarch, i), + (addresses_known) ? "address" : "offset", + paddress (gdbarch, cache->saved_regs[i].addr ())); } } @@ -1686,8 +1665,7 @@ arc_print_frame_cache (struct gdbarch *gdbarch, const char *message, static struct arc_frame_cache * arc_make_frame_cache (struct frame_info *this_frame) { - if (arc_debug) - debug_printf ("arc: frame_cache\n"); + arc_debug_printf ("called"); struct gdbarch *gdbarch = get_frame_arch (this_frame); @@ -1755,8 +1733,7 @@ static void arc_frame_this_id (struct frame_info *this_frame, void **this_cache, struct frame_id *this_id) { - if (arc_debug) - debug_printf ("arc: frame_this_id\n"); + arc_debug_printf ("called"); struct gdbarch *gdbarch = get_frame_arch (this_frame); @@ -1851,8 +1828,7 @@ arc_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum, static struct arc_frame_cache * arc_make_sigtramp_frame_cache (struct frame_info *this_frame) { - if (arc_debug) - debug_printf ("arc: sigtramp_frame_cache\n"); + arc_debug_printf ("called"); struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (this_frame)); @@ -1891,8 +1867,7 @@ static void arc_sigtramp_frame_this_id (struct frame_info *this_frame, void **this_cache, struct frame_id *this_id) { - if (arc_debug) - debug_printf ("arc: sigtramp_frame_this_id\n"); + arc_debug_printf ("called"); if (*this_cache == NULL) *this_cache = arc_make_sigtramp_frame_cache (this_frame); @@ -1911,8 +1886,7 @@ static struct value * arc_sigtramp_frame_prev_register (struct frame_info *this_frame, void **this_cache, int regnum) { - if (arc_debug) - debug_printf ("arc: sigtramp_frame_prev_register (regnum = %d)\n", regnum); + arc_debug_printf ("regnum = %d", regnum); /* Make sure we've initialized the cache. */ if (*this_cache == NULL) @@ -1932,8 +1906,7 @@ arc_sigtramp_frame_sniffer (const struct frame_unwind *self, { struct gdbarch_tdep *tdep; - if (arc_debug) - debug_printf ("arc: sigtramp_frame_sniffer\n"); + arc_debug_printf ("called"); tdep = gdbarch_tdep (get_frame_arch (this_frame)); @@ -2193,8 +2166,7 @@ arc_tdesc_init (struct gdbarch_info info, const struct target_desc **tdesc, tdesc_arch_data_up *tdesc_data) { const struct target_desc *tdesc_loc = info.target_desc; - if (arc_debug) - debug_printf ("arc: Target description initialization.\n"); + arc_debug_printf ("Target description initialization."); /* If target doesn't provide a description, use the default ones. */ if (!tdesc_has_registers (tdesc_loc)) @@ -2206,8 +2178,7 @@ arc_tdesc_init (struct gdbarch_info info, const struct target_desc **tdesc, } gdb_assert (tdesc_loc != nullptr); - if (arc_debug) - debug_printf ("arc: Have got a target description\n"); + arc_debug_printf ("Have got a target description"); const struct tdesc_feature *feature_core = tdesc_find_feature (tdesc_loc, ARC_CORE_FEATURE_NAME); @@ -2253,8 +2224,7 @@ arc_tdesc_init (struct gdbarch_info info, const struct target_desc **tdesc, if (!valid_p) { - if (arc_debug) - debug_printf ("arc: Target description is not valid\n"); + arc_debug_printf ("Target description is not valid"); return false; } @@ -2300,8 +2270,7 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) const struct target_desc *tdesc; tdesc_arch_data_up tdesc_data; - if (arc_debug) - debug_printf ("arc: Architecture initialization.\n"); + arc_debug_printf ("Architecture initialization."); if (!arc_tdesc_init (info, &tdesc, &tdesc_data)) return nullptr; diff --git a/gdb/arc-tdep.h b/gdb/arc-tdep.h index 575cd28cacd..8bb005cc7d4 100644 --- a/gdb/arc-tdep.h +++ b/gdb/arc-tdep.h @@ -114,6 +114,11 @@ enum arc_regnum extern bool arc_debug; +/* Print an "arc" debug statement. */ + +#define arc_debug_printf(fmt, ...) \ + debug_prefixed_printf_cond (arc_debug, "arc", fmt, ##__VA_ARGS__) + /* Target-dependent information. */ struct gdbarch_tdep -- 2.30.2