Fix for "dis" command to correctly display the offset of disassembly code

For gdb-10.2, the disassembly code may start with "=>", which needs to
be stripped when calculating the address. Otherwise, parsing the address
will fail because the current code always assumes that it starts with the
"0x". For example:

  crash> gdb disassemble 0xffffffffa2317add
  Dump of assembler code for function native_queued_spin_lock_slowpath:
     ...
     0xffffffffa2317ad3 <+35>:    mov    %edx,%eax
     0xffffffffa2317ad5 <+37>:    lock cmpxchg %ecx,(%rdi)
  => 0xffffffffa2317ad9 <+41>:    cmp    %eax,%edx
     0xffffffffa2317adb <+43>:    jne    0xffffffffa2317ac0 ...
     0xffffffffa2317add <+45>:    pop    %rbp
     ...

Without the patch:
  crash> dis 0xffffffffa2317add -r | tail -5
  0xffffffffa2317ad3 <native_queued_spin_lock_slowpath+35>:	mov    %edx,%eax
  0xffffffffa2317ad5 <native_queued_spin_lock_slowpath+37>:	lock cmpxchg %ecx,(%rdi)
  0xffffffffa2317ad5 <native_queued_spin_lock_slowpath+37>:	cmp    %eax,%edx
                                                       ^^
  0xffffffffa2317adb <native_queued_spin_lock_slowpath+43>:	jne    0xffffffffa2317ac0 ...
  0xffffffffa2317add <native_queued_spin_lock_slowpath+45>:	pop    %rbp

With the patch:

  crash> dis 0xffffffffa2317add -r | tail -5
  0xffffffffa2317ad3 <native_queued_spin_lock_slowpath+35>:	mov    %edx,%eax
  0xffffffffa2317ad5 <native_queued_spin_lock_slowpath+37>:	lock cmpxchg %ecx,(%rdi)
  0xffffffffa2317ad9 <native_queued_spin_lock_slowpath+41>:	cmp    %eax,%edx
  0xffffffffa2317adb <native_queued_spin_lock_slowpath+43>:	jne    0xffffffffa2317ac0 ...
  0xffffffffa2317add <native_queued_spin_lock_slowpath+45>:	pop    %rbp

Reported-by: Vernon Lovejoy <vlovejoy@redhat.com>
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
This commit is contained in:
Lianbo Jiang 2023-02-21 11:03:26 +08:00 committed by Kazuhito Hagio
parent e0e6e4a7ee
commit 59c1981819
1 changed files with 4 additions and 0 deletions

View File

@ -2112,6 +2112,10 @@ cmd_dis(void)
rewind(pc->tmpfile);
while (fgets(buf2, BUFSIZE, pc->tmpfile)) {
if (STRNEQ(buf2, "=>"))
shift_string_left(buf2, 2);
strip_beginning_whitespace(buf2);
if (do_load_module_filter)