[binutils-gdb] gdb: extract a function out of do_examine_next_address
Tankut Baris Aktemur via Gdb-cvs <[email protected]>
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=400870cfe044fd2415f38b0f1799446d1c96b901 commit 400870cfe044fd2415f38b0f1799446d1c96b901 Author: Tankut Baris Aktemur <[email protected]> Date: Tue Mar 24 16:56:01 2026 +0100 gdb: extract a function out of do_examine_next_address Extract function `format_to_type` out of `do_examine_next_address`. This is a preparatory refactoring for the next patch. Approved-By: Tom Tromey <[email protected]> Diff: --- gdb/printcmd.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/gdb/printcmd.c b/gdb/printcmd.c index e3840979640..49f7209ca40 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -987,16 +987,15 @@ find_string_backward (struct gdbarch *gdbarch, return string_start_addr; } -/* Examine data at address NEXT_ADDRESS in format FMT. - Fetch it from memory and print on gdb_stdout. */ +/* Given format FMT and architecture GDBARCH, return the corresponding + value type. */ -static void -do_examine_next_address (struct format_data fmt) +static type * +format_to_type (format_data fmt, gdbarch *gdbarch) { char format = fmt.format; char size = fmt.size; type *val_type = nullptr; - gdbarch *gdbarch = next_gdbarch; if (size == 'a') { @@ -1054,6 +1053,43 @@ do_examine_next_address (struct format_data fmt) = builtin_type (gdbarch)->builtin_func_ptr->target_type (); } + gdb_assert (val_type != nullptr); + return val_type; +} + +/* Examine data at address NEXT_ADDRESS in format FMT. + Fetch it from memory and print on gdb_stdout. */ + +static void +do_examine_next_address (struct format_data fmt) +{ + char format = fmt.format; + type *val_type = format_to_type (fmt, next_gdbarch); + gdbarch *gdbarch = next_gdbarch; + + char size; + switch (val_type->length ()) + { + case 1: + size = 'b'; + break; + + case 2: + size = 'h'; + break; + + case 4: + size = 'w'; + break; + + case 8: + size = 'g'; + break; + + default: + gdb_assert_not_reached ("unexpected type length for next_address"); + } + int maxelts = 8; if (size == 'w') maxelts = 4;