Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Paul Pluzhnikov <ppluzhnikov@google.com>
To: Paul Pluzhnikov <ppluzhnikov@google.com>, gdb-patches@sourceware.org
Subject: Re: [RFC][patch] Allow to disassemble line.
Date: Fri, 16 Oct 2009 23:07:00 -0000	[thread overview]
Message-ID: <8ac60eac0910161607k55fee22cs379c5b7635d7b6a@mail.gmail.com> (raw)
In-Reply-To: <8ac60eac0910080952p46f15693x6ed339473db0139d@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 5783 bytes --]

On Thu, Oct 8, 2009 at 9:52 AM, Paul Pluzhnikov <ppluzhnikov@google.com> wrote:

> On Thu, Oct 8, 2009 at 9:23 AM, Daniel Jacobowitz <drow@false.org> wrote:
>
>> I'd mildly prefer changing the behavior of GDB - but only if we can
>> get an additional enhancement that I don't think we have yet: "*" at
>> the PC...
>
> That sounds good. I'll try to implement that.

Here my attempt to implement that.

I am guessing that it is flawed, as it possibly breaks something in MI
(which I don't understand yet).

It also breaks quite a few test cases -- I'll adjust expected patterns if
it is decided to go ahead with this.

I should say that from CLI perspective I like this very much. On x86,
often you need to examine 10 or so instructions before the crash point.

I usually do 'x/10i $pc-15' (as instruction size is not fixed), and then
"hunt" for the current PC in the resulting output. This patch makes it so
much easier:

(top) x/10i $pc-15
  0x54d212 <catch_errors+54>:   mov    -0x10(%rbp),%edi
  0x54d215 <catch_errors+57>:   mov    $0x1,%esi
  0x54d21a <catch_errors+62>:   callq  0x452c38 <__sigsetjmp@plt>
  0x54d21f <catch_errors+67>:   jmp    0x54d237 <catch_errors+91>
* 0x54d221 <catch_errors+69>:   mov    -0x30(%rbp),%rdi
  0x54d225 <catch_errors+73>:   mov    -0x28(%rbp),%rax
  0x54d229 <catch_errors+77>:   callq  *%rax
  0x54d22b <catch_errors+79>:   mov    %eax,-0x4(%rbp)
  0x54d22e <catch_errors+82>:   callq  0x54c9c0
<exceptions_state_mc_action_iter_1>
  0x54d233 <catch_errors+87>:   test   %eax,%eax

I also like how 'disassemble-next-line on' works:

(top) set disassemble-next-line on
(top) ni
0x000000000054d225      510           val = func (func_args);
  0x000000000054d221 <catch_errors+69>:  48 8b 7d d0    mov    -0x30(%rbp),%rdi
* 0x000000000054d225 <catch_errors+73>:  48 8b 45 d8    mov    -0x28(%rbp),%rax
  0x000000000054d229 <catch_errors+77>:  ff d0  callq  *%rax
  0x000000000054d22b <catch_errors+79>:  89 45 fc       mov    %eax,-0x4(%rbp)
(top) ni
0x000000000054d229      510           val = func (func_args);
  0x000000000054d221 <catch_errors+69>:  48 8b 7d d0    mov    -0x30(%rbp),%rdi
  0x000000000054d225 <catch_errors+73>:  48 8b 45 d8    mov    -0x28(%rbp),%rax
* 0x000000000054d229 <catch_errors+77>:  ff d0  callq  *%rax
  0x000000000054d22b <catch_errors+79>:  89 45 fc       mov    %eax,-0x4(%rbp)

As well as how 'disas' works:

(top) disas
Dump of assembler code for function catch_errors:
  0x000000000054d1dc <catch_errors+0>:  push   %rbp
  0x000000000054d1dd <catch_errors+1>:  mov    %rsp,%rbp
  0x000000000054d1e0 <catch_errors+4>:  sub    $0x40,%rsp
  0x000000000054d1e4 <catch_errors+8>:  mov    %rdi,-0x28(%rbp)
  0x000000000054d1e8 <catch_errors+12>: mov    %rsi,-0x30(%rbp)
  0x000000000054d1ec <catch_errors+16>: mov    %rdx,-0x38(%rbp)
  0x000000000054d1f0 <catch_errors+20>: mov    %ecx,-0x3c(%rbp)
  0x000000000054d1f3 <catch_errors+23>: movl   $0x0,-0x4(%rbp)
  0x000000000054d1fa <catch_errors+30>: mov    0x56e1bf(%rip),%rdi
   # 0xabb3c0 <uiout>
  0x000000000054d201 <catch_errors+37>: mov    -0x3c(%rbp),%edx
  0x000000000054d204 <catch_errors+40>: lea    -0x20(%rbp),%rsi
  0x000000000054d208 <catch_errors+44>: callq  0x54c678
<exceptions_state_mc_init>
  0x000000000054d20d <catch_errors+49>: mov    %rax,-0x10(%rbp)
  0x000000000054d211 <catch_errors+53>: mov    -0x10(%rbp),%rdi
  0x000000000054d215 <catch_errors+57>: mov    $0x1,%esi
  0x000000000054d21a <catch_errors+62>: callq  0x452c38 <__sigsetjmp@plt>
  0x000000000054d21f <catch_errors+67>: jmp    0x54d237 <catch_errors+91>
  0x000000000054d221 <catch_errors+69>: mov    -0x30(%rbp),%rdi
  0x000000000054d225 <catch_errors+73>: mov    -0x28(%rbp),%rax
* 0x000000000054d229 <catch_errors+77>: callq  *%rax
  0x000000000054d22b <catch_errors+79>: mov    %eax,-0x4(%rbp)
  0x000000000054d22e <catch_errors+82>: callq  0x54c9c0
<exceptions_state_mc_action_iter_1>
  0x000000000054d233 <catch_errors+87>: test   %eax,%eax
  0x000000000054d235 <catch_errors+89>: jne    0x54d221 <catch_errors+69>
  0x000000000054d237 <catch_errors+91>: callq  0x54c9b0
<exceptions_state_mc_action_iter>
  0x000000000054d23c <catch_errors+96>: test   %eax,%eax
  0x000000000054d23e <catch_errors+98>: jne    0x54d22e <catch_errors+82>
  0x000000000054d240 <catch_errors+100>:        mov
0x593721(%rip),%rdi        # 0xae0968 <gdb_stderr>
  0x000000000054d247 <catch_errors+107>:        mov    -0x20(%rbp),%rdx
  0x000000000054d24b <catch_errors+111>:        mov    -0x18(%rbp),%rcx
  0x000000000054d24f <catch_errors+115>:        mov    -0x38(%rbp),%rsi
  0x000000000054d253 <catch_errors+119>:        callq  0x54cdea
<print_any_exception>
  0x000000000054d258 <catch_errors+124>:        mov    -0x20(%rbp),%eax
  0x000000000054d25b <catch_errors+127>:        test   %eax,%eax
  0x000000000054d25d <catch_errors+129>:        je     0x54d268
<catch_errors+140>
  0x000000000054d25f <catch_errors+131>:        movl   $0x0,-0x40(%rbp)
  0x000000000054d266 <catch_errors+138>:        jmp    0x54d26e
<catch_errors+146>
  0x000000000054d268 <catch_errors+140>:        mov    -0x4(%rbp),%eax
  0x000000000054d26b <catch_errors+143>:        mov    %eax,-0x40(%rbp)
  0x000000000054d26e <catch_errors+146>:        mov    -0x40(%rbp),%eax
  0x000000000054d271 <catch_errors+149>:        leaveq
  0x000000000054d272 <catch_errors+150>:        retq
End of assembler dump.


Thanks,
-- 
Paul Pluzhnikov

2009-10-16  Paul Pluzhnikov  <ppluzhnikov@google.com>

	* defs.h (pc_prefix): New prototype.
	* disasm.c (dump_insns): Identify instruction address as such.
	* ui-out.c (ui_out_field_core_addr): Highlight current instruction.
	* printcmd.c (do_examine): Likewise.
	(pc_prefix, print_pc_prefix): New function.
	* stack.c (print_frame_info): Disassemble entire current line.

[-- Attachment #2: gdb-disas-20091016.txt --]
[-- Type: text/plain, Size: 3066 bytes --]

Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.255
diff -u -p -u -r1.255 defs.h
--- defs.h	22 Sep 2009 22:34:17 -0000	1.255
+++ defs.h	16 Oct 2009 22:37:36 -0000
@@ -608,6 +608,7 @@ extern int build_address_symbolic (CORE_
 				   int *unmapped);
 
 extern void print_address (struct gdbarch *, CORE_ADDR, struct ui_file *);
+extern const char *pc_prefix (CORE_ADDR);
 
 /* From source.c */
 
Index: disasm.c
===================================================================
RCS file: /cvs/src/src/gdb/disasm.c,v
retrieving revision 1.33
diff -u -p -u -r1.33 disasm.c
--- disasm.c	11 Jul 2009 14:04:23 -0000	1.33
+++ disasm.c	16 Oct 2009 22:37:36 -0000
@@ -113,7 +113,7 @@ dump_insns (struct gdbarch *gdbarch, str
 	    num_displayed++;
 	}
       ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
-      ui_out_field_core_addr (uiout, "address", gdbarch, pc);
+      ui_out_field_core_addr (uiout, "pc_addr", gdbarch, pc);
 
       if (!build_address_symbolic (pc, 0, &name, &offset, &filename,
 				   &line, &unmapped))
Index: printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.164
diff -u -p -u -r1.164 printcmd.c
--- printcmd.c	2 Jul 2009 17:25:58 -0000	1.164
+++ printcmd.c	16 Oct 2009 22:37:36 -0000
@@ -716,6 +716,32 @@ print_address (struct gdbarch *gdbarch,
   print_address_symbolic (addr, stream, asm_demangle, " ");
 }
 
+/* Return a prefix for instruction address:
+   "* " for current instruction, else "  ".  */
+
+const char *
+pc_prefix (CORE_ADDR addr)
+{
+  if (has_stack_frames ())
+    {
+      struct frame_info *frame;
+      CORE_ADDR pc;
+
+      frame = get_selected_frame (NULL);
+      pc = get_frame_pc (frame);
+
+      if (pc == addr)
+	return "* ";
+    }
+  return "  ";
+}
+
+static void
+print_pc_prefix (CORE_ADDR addr, struct ui_file *stream)
+{
+  fputs_filtered (pc_prefix (addr), stream);
+}
+
 /* Print address ADDR symbolically on STREAM.  Parameter DEMANGLE
    controls whether to print the symbolic name "raw" or demangled.
    Global setting "addressprint" controls whether to print hex address
@@ -808,6 +834,8 @@ do_examine (struct format_data fmt, stru
   while (count > 0)
     {
       QUIT;
+      if (format == 'i')
+	print_pc_prefix (next_address, gdb_stdout);
       print_address (next_gdbarch, next_address, gdb_stdout);
       printf_filtered (":");
       for (i = maxelts;
Index: ui-out.c
===================================================================
RCS file: /cvs/src/src/gdb/ui-out.c,v
retrieving revision 1.43
diff -u -p -u -r1.43 ui-out.c
--- ui-out.c	2 Jul 2009 17:21:07 -0000	1.43
+++ ui-out.c	16 Oct 2009 22:37:36 -0000
@@ -505,6 +505,9 @@ ui_out_field_core_addr (struct ui_out *u
   else
     strcpy (addstr, hex_string_custom (address, 16));
 
+  if (strcmp (fldname, "pc_addr") == 0)
+    ui_out_text (uiout, pc_prefix (address));
+
   ui_out_field_string (uiout, fldname, addstr);
 }
 

  parent reply	other threads:[~2009-10-16 23:07 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-02  0:50 Paul Pluzhnikov
2009-10-02  6:52 ` Joel Brobecker
2009-10-02 18:31   ` Paul Pluzhnikov
2009-10-02 18:49     ` Joel Brobecker
2009-10-02 15:17 ` Tom Tromey
2009-10-08 16:16 ` Paul Pluzhnikov
2009-10-08 16:23   ` Daniel Jacobowitz
2009-10-08 16:25     ` Joel Brobecker
2009-10-08 16:52     ` Paul Pluzhnikov
2009-10-08 17:29       ` Daniel Jacobowitz
2009-10-08 17:33         ` Joel Brobecker
2009-10-16 23:07       ` Paul Pluzhnikov [this message]
2009-10-16 23:11         ` Paul Pluzhnikov
2009-10-17  8:33           ` Eli Zaretskii
2009-10-17 15:50             ` Paul Pluzhnikov
2009-10-17 16:49               ` Eli Zaretskii
2009-10-17 17:08                 ` Paul Pluzhnikov
2009-10-17 19:55                   ` Eli Zaretskii
2009-10-19 17:47         ` Tom Tromey
2009-10-19 18:09           ` Paul Pluzhnikov
2009-10-19 18:20             ` Paul Pluzhnikov
2009-10-19 18:30             ` Tom Tromey
2009-10-21  0:22               ` Paul Pluzhnikov
2009-10-21  4:07                 ` Eli Zaretskii
2009-10-21 18:06                   ` Paul Pluzhnikov
2009-10-21 18:16                     ` Eli Zaretskii
2009-10-21 17:24                 ` Tom Tromey
2009-10-19 18:49             ` Daniel Jacobowitz
2009-10-19 19:40               ` Joel Brobecker
2009-10-19 19:56                 ` Daniel Jacobowitz
2009-10-19 20:03                   ` Tom Tromey
2009-10-19 20:10                     ` Joel Brobecker
2009-10-19 20:23                       ` Paul Pluzhnikov
2009-10-19 20:47                         ` Daniel Jacobowitz
2009-10-19 19:40               ` Eli Zaretskii
2009-10-19 19:55                 ` Daniel Jacobowitz
2009-10-20 16:04               ` Tom Tromey
2009-10-08 16:24   ` Joel Brobecker
2009-10-08 17:16     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8ac60eac0910161607k55fee22cs379c5b7635d7b6a@mail.gmail.com \
    --to=ppluzhnikov@google.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox