Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Commit ed4227b

Browse files
committed
Reimplement support for "maint print registers" with no running inferior yet
A following patch will change the default target_thread_architecture method, like this: struct gdbarch * default_thread_architecture (struct target_ops *ops, ptid_t ptid) { - return target_gdbarch (); + inferior *inf = find_inferior_ptid (ptid); + gdb_assert (inf != NULL); + return inf->gdbarch; } This is because target_gdbarch is really just current_inferior()->gdbarch, and it's wrong to return that architecture when the inferior of the passed in PTID is NOT the current inferior -- the inferior for PTID may be running a different architecture. E.g., a mix of 64-bit and 32-bit inferiors in the same debug session. Doing that change above however exposes a problem in "maint print registers", caught be the testsuite: -PASS: gdb.base/maint.exp: maint print registers +FAIL: gdb.base/maint.exp: maint print registers (GDB internal error) ... gdb/inferior.c:309: internal-error: inferior* find_inferior_pid(int): Assertion `pid != 0' failed. A problem internal to GDB has been detected, The call stack looks like this: #0 0x000000000068b707 in internal_error(char const*, int, char const*, ...) (file=0xa9b958 "gdb/inferior.c", line=309, fmt=0xa9b8e0 "%s: Assertion `%s' failed.") at gdb/common/errors.c:54 #1 0x00000000006e1c40 in find_inferior_pid(int) (pid=0) at gdb/inferior.c:309 #2 0x00000000006e1c8d in find_inferior_ptid(ptid_t) (ptid=...) at gdb/inferior.c:323 #3 0x00000000007c18dc in default_thread_architecture(target_ops*, ptid_t) (ops=0xf86d60 <dummy_target>, ptid=...) at gdb/target.c:3134 #4 0x00000000007b5414 in delegate_thread_architecture(target_ops*, ptid_t) (self=0xf86d60 <dummy_target>, arg1=...) at gdb/target-delegates.c:2527 #5 0x00000000007647b3 in get_thread_regcache(ptid_t) (ptid=...) at gdb/regcache.c:466 #6 0x00000000007647ff in get_current_regcache() () at gdb/regcache.c:475 #7 0x0000000000767495 in regcache_print(char const*, regcache_dump_what) (args=0x0, what_to_dump=regcache_dump_none) at gdb/regcache.c:1599 #8 0x0000000000767550 in maintenance_print_registers(char const*, int) (args=0x0, from_tty=1) at gdb/regcache.c:1613 I.e., the test does "maint print registers" while the inferior is not running yet. This is expected to work, and there's already a hack in get_thread_arch_regcache to make it work. Instead of pilling on hacks in the internal of regcache and target_ops, this commit moves the null_ptid special casing to where it belongs -- higher up in the call chain in the implementation of "maint print registers" & co directly. gdb/ChangeLog: 2017-10-04 Pedro Alves <[email protected]> * regcache.c (get_thread_arch_regcache): Remove null_ptid special case. (regcache_print): Handle !target_has_registers here instead.
1 parent 55b11dd commit ed4227b

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

gdb/ChangeLog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2017-10-04 Pedro Alves <[email protected]>
2+
3+
* regcache.c (get_thread_arch_regcache): Remove null_ptid special
4+
case.
5+
(regcache_print): Handle !target_has_registers here instead.
6+
17
2017-10-04 Pedro Alves <[email protected]>
28

39
* frame.c (create_test_frame): Delete.

gdb/regcache.c

+18-15
Original file line numberDiff line numberDiff line change
@@ -439,17 +439,7 @@ get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
439439
struct regcache *
440440
get_thread_arch_regcache (ptid_t ptid, struct gdbarch *gdbarch)
441441
{
442-
struct address_space *aspace;
443-
444-
/* For the benefit of "maint print registers" & co when debugging an
445-
executable, allow dumping the regcache even when there is no
446-
thread selected (target_thread_address_space internal-errors if
447-
no address space is found). Note that normal user commands will
448-
fail higher up on the call stack due to no
449-
target_has_registers. */
450-
aspace = (ptid_equal (null_ptid, ptid)
451-
? NULL
452-
: target_thread_address_space (ptid));
442+
address_space *aspace = target_thread_address_space (ptid);
453443

454444
return get_thread_arch_aspace_regcache (ptid, gdbarch, aspace);
455445
}
@@ -1595,15 +1585,28 @@ regcache::dump (ui_file *file, enum regcache_dump_what what_to_dump)
15951585
static void
15961586
regcache_print (const char *args, enum regcache_dump_what what_to_dump)
15971587
{
1588+
/* Where to send output. */
1589+
stdio_file file;
1590+
ui_file *out;
1591+
15981592
if (args == NULL)
1599-
get_current_regcache ()->dump (gdb_stdout, what_to_dump);
1593+
out = gdb_stdout;
16001594
else
16011595
{
1602-
stdio_file file;
1603-
16041596
if (!file.open (args, "w"))
16051597
perror_with_name (_("maintenance print architecture"));
1606-
get_current_regcache ()->dump (&file, what_to_dump);
1598+
out = &file;
1599+
}
1600+
1601+
if (target_has_registers)
1602+
get_current_regcache ()->dump (out, what_to_dump);
1603+
else
1604+
{
1605+
/* For the benefit of "maint print registers" & co when
1606+
debugging an executable, allow dumping a regcache even when
1607+
there is no thread selected / no registers. */
1608+
regcache dummy_regs (target_gdbarch (), nullptr);
1609+
dummy_regs.dump (out, what_to_dump);
16071610
}
16081611
}
16091612

0 commit comments

Comments
 (0)