From a6e5abae4e9e845e6e69e07f755c0805558dcd63 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Wed, 22 Mar 2023 17:22:51 +0000 Subject: gdb: move displaced_step_dump_bytes into gdbsupport (and rename) It was pointed out during review of another patch that the function displaced_step_dump_bytes really isn't specific to displaced stepping, and should really get a more generic name and move into gdbsupport/. This commit does just that. The function is renamed to bytes_to_string and is moved into gdbsupport/common-utils.{cc,h}. The function implementation doesn't really change. Much... ... I have updated the function to take an array view, which makes it slightly easier to call in a couple of places where we already have a gdb::bytes_vector. I've then added an inline wrapper to convert a raw pointer and length into an array view, which is used in places where we don't easily have a gdb::bytes_vector (or similar). Updated all users of displaced_step_dump_bytes. There should be no user visible changes after this commit. Finally, I ended up having to add an include of gdb_assert.h into array-view.h. When I include array-view.h into common-utils.h I ran into build problems because array-view.h calls gdb_assert. Approved-By: Simon Marchi --- gdb/amd64-tdep.c | 2 +- gdb/displaced-stepping.c | 3 +-- gdb/i386-tdep.c | 2 +- gdb/infrun.c | 24 ++---------------------- gdb/infrun.h | 3 --- gdb/rs6000-tdep.c | 2 +- gdb/s390-tdep.c | 2 +- 7 files changed, 7 insertions(+), 31 deletions(-) (limited to 'gdb') diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c index 81665e5..228b751 100644 --- a/gdb/amd64-tdep.c +++ b/gdb/amd64-tdep.c @@ -1526,7 +1526,7 @@ amd64_displaced_step_copy_insn (struct gdbarch *gdbarch, displaced_debug_printf ("copy %s->%s: %s", paddress (gdbarch, from), paddress (gdbarch, to), - displaced_step_dump_bytes (buf, len).c_str ()); + bytes_to_string (buf, len).c_str ()); /* This is a work around for a problem with g++ 4.8. */ return displaced_step_copy_insn_closure_up (dsc.release ()); diff --git a/gdb/displaced-stepping.c b/gdb/displaced-stepping.c index 3fefdf3..c268884 100644 --- a/gdb/displaced-stepping.c +++ b/gdb/displaced-stepping.c @@ -122,8 +122,7 @@ displaced_step_buffers::prepare (thread_info *thread, CORE_ADDR &displaced_pc) displaced_debug_printf ("saved %s: %s", paddress (arch, buffer->addr), - displaced_step_dump_bytes - (buffer->saved_copy.data (), len).c_str ()); + bytes_to_string (buffer->saved_copy).c_str ()); /* Save this in a local variable first, so it's released if code below throws. */ diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index 96c04c1..e93479c 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -830,7 +830,7 @@ i386_displaced_step_copy_insn (struct gdbarch *gdbarch, displaced_debug_printf ("%s->%s: %s", paddress (gdbarch, from), paddress (gdbarch, to), - displaced_step_dump_bytes (buf, len).c_str ()); + bytes_to_string (buf, len).c_str ()); /* This is a work around for a problem with g++ 4.8. */ return displaced_step_copy_insn_closure_up (closure.release ()); diff --git a/gdb/infrun.c b/gdb/infrun.c index 5ccdc0c..8a8439f 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -1725,24 +1725,6 @@ displaced_step_reset (displaced_step_thread_state *displaced) using displaced_step_reset_cleanup = FORWARD_SCOPE_EXIT (displaced_step_reset); -/* See infrun.h. */ - -std::string -displaced_step_dump_bytes (const gdb_byte *buf, size_t len) -{ - std::string ret; - - for (size_t i = 0; i < len; i++) - { - if (i == 0) - ret += string_printf ("%02x", buf[i]); - else - ret += string_printf (" %02x", buf[i]); - } - - return ret; -} - /* Prepare to single-step, using displaced stepping. Note that we cannot use displaced stepping when we have a signal to @@ -1820,8 +1802,7 @@ displaced_step_prepare_throw (thread_info *tp) gdb::byte_vector insn_buf (dislen); read_memory (original_pc, insn_buf.data (), insn_buf.size ()); - std::string insn_bytes - = displaced_step_dump_bytes (insn_buf.data (), insn_buf.size ()); + std::string insn_bytes = bytes_to_string (insn_buf); displaced_debug_printf ("original insn %s: %s \t %s", paddress (gdbarch, original_pc), @@ -1902,8 +1883,7 @@ displaced_step_prepare_throw (thread_info *tp) gdb::byte_vector insn_buf (dislen); read_memory (addr, insn_buf.data (), insn_buf.size ()); - std::string insn_bytes - = displaced_step_dump_bytes (insn_buf.data (), insn_buf.size ()); + std::string insn_bytes = bytes_to_string (insn_buf); std::string insn_str = tmp_stream.release (); displaced_debug_printf ("replacement insn %s: %s \t %s", paddress (gdbarch, addr), diff --git a/gdb/infrun.h b/gdb/infrun.h index 5219063..9b3c896 100644 --- a/gdb/infrun.h +++ b/gdb/infrun.h @@ -270,9 +270,6 @@ extern void update_signals_program_target (void); $_exitsignal. */ extern void clear_exit_convenience_vars (void); -/* Dump LEN bytes at BUF in hex to a string and return it. */ -extern std::string displaced_step_dump_bytes (const gdb_byte *buf, size_t len); - extern void update_observer_mode (void); extern void signal_catch_update (const unsigned int *); diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c index 8b40004..b071f38 100644 --- a/gdb/rs6000-tdep.c +++ b/gdb/rs6000-tdep.c @@ -940,7 +940,7 @@ ppc_displaced_step_copy_insn (struct gdbarch *gdbarch, displaced_debug_printf ("copy %s->%s: %s", paddress (gdbarch, from), paddress (gdbarch, to), - displaced_step_dump_bytes (buf, len).c_str ()); + bytes_to_string (buf, len).c_str ()); /* This is a work around for a problem with g++ 4.8. */ return displaced_step_copy_insn_closure_up (closure.release ()); diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c index cab1757..081a8b6 100644 --- a/gdb/s390-tdep.c +++ b/gdb/s390-tdep.c @@ -469,7 +469,7 @@ s390_displaced_step_copy_insn (struct gdbarch *gdbarch, displaced_debug_printf ("copy %s->%s: %s", paddress (gdbarch, from), paddress (gdbarch, to), - displaced_step_dump_bytes (buf, len).c_str ()); + bytes_to_string (buf, len).c_str ()); /* This is a work around for a problem with g++ 4.8. */ return displaced_step_copy_insn_closure_up (closure.release ()); -- cgit v1.1