[RFC] disassemble-next-line

teawater
2009-03-08T05:34:49Z

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

Hi guys,

This is the patch for the function to output assembly codes for next line.
I this a rfc and doesn't include doc because we still a lot of thing
is not decided. Such as the name, the behavior and maybe something
else.

I didn't add disassemble-next-line-max because I want output a warning
this message is cut if the number is bigger than max.
But make sure it's cut or not is not easy. And there is already a
filter when output the assembly codes.
So I think maybe we don't need it.

Please send your comment. Thanks a lot. :)

Thanks,
Hui

On Thu, Mar 5, 2009 at 10:41, teawater <teawater@gmail.com> wrote:
>
> Thanks guys,
>
> For the people that want extend disassemble:
> Output assembly codes of next-line is just one part of this idea.
>
> We still have another part:
> 1. Auto mode, output assembly codes only if there is not line message
> for current pc.
> For example:
> (gdb) si
> 0x080483ee      24              b = printf ("a = %d b = %d c = %d\n", a, b, c);
> (gdb) si
> 0x080482d8 in printf@plt ()
> Current language:  auto; currently asm
> 0x080482d8 <printf@plt+0>:      jmp    *0x8049670
> (gdb) si
> 0x080482de in printf@plt ()
> 0x080482de <printf@plt+6>:      push   $0x10
>
> I think maybe is can be default option of gdb.  Add it to display with itself?
>
>
> 2. Output assembly codes number limit.
> This idea form Doug:
> Also, the user might want to set a limit on the number of lines of
> disassembly displayed.
> If cut short gdb could print "[output cut short due to `set
> dissemble-next-line-max 10']" (or some such).
>
> I think maybe it need output something like "This message is cut ...
> you can set it with ...".
>
>
> 3. Special for optimized code.
> This idea form Doug too:
> For debugging optimized code, maybe it'd be nice if gdb determined
> there were more (discontiguous) lines of disassembly to display for
> the current source line and notified the user (by printing
> "discontiguous source line" or some such) before and/or after the
> output.
>
>
>
> I think maybe is too much thing for disassemble.
>
>
>
> Thanks,
> Hui
>
>
>
> On Thu, Mar 5, 2009 at 07:40, Tom Tromey <tromey@redhat.com> wrote:
> >>>>>> "Daniel" == Daniel Jacobowitz <drow@false.org> writes:
> >
> >>> Right, I thought about something that begins with "disassemble", but
> >>> didn't want to shoot our completion habits in the foot, since
> >>> currently typing just "disas TAB" is all I need to get disassembly.
> >
> > Daniel> I agree we don't want to change that binding (I use it all the time).
> > Daniel> But is it a problem?  This would be under set, if I understand right.
> >
> > Yeah, this sounds reasonable to me.
> > I'd prefer to have some word like "disassemble" in the parameter name.
> >
> > Tom
> >

[-- Attachment #2: disassemble-next-line.txt --]
[-- Type: text/plain, Size: 4080 bytes --]

---
stack.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 85 insertions(+)

--- a/stack.c
+++ b/stack.c
@@ -45,6 +45,7 @@
#include "valprint.h"
#include "gdbthread.h"
#include "cp-support.h"
+#include "disasm.h"

#include "gdb_assert.h"
#include <ctype.h>
@@ -456,6 +457,53 @@ set_current_sal_from_frame (struct frame
}
}

+/* Enum strings for "set|show disassemble-next-line". */
+
+static const char disassemble_next_line_auto[] = "auto";
+static const char disassemble_next_line_on[] = "on";
+static const char disassemble_next_line_off[] = "off";
+static const char *disassemble_next_line_enum[] =
+{
+ disassemble_next_line_auto,
+ disassemble_next_line_on,
+ disassemble_next_line_off,
+ NULL,
+};
+
+/* If ON, GDB will output the assembly codes of next line.
+ If OFF, GDB will not do it.
+ doesn't support it, GDB will instead use the traditional
+ If AUTO (which is the default), GDB will output a assembly code
+ at current address if there is not line message. */
+
+static const char *disassemble_next_line = disassemble_next_line_on;
+
+static void
+show_disassemble_next_line (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c,
+ const char *value)
+{
+ fprintf_filtered (file, _("\
+Debugger's willingness to use disassemble-next-line is %s.\n"), value);
+}
+
+/* Show assembly codes; stub for catch_errors. */
+
+struct gdb_disassembly_stub_args
+{
+ int how_many;
+ CORE_ADDR low;
+ CORE_ADDR high;
+};
+
+static int
+gdb_disassembly_stub (void *args)
+{
+ struct gdb_disassembly_stub_args *p = args;
+ gdb_disassembly (uiout, 0, 0, 0, p->how_many, p->low, p->high);
+ return 0;
+}
+
/* Print information about frame FRAME. The output is format according
to PRINT_LEVEL and PRINT_WHAT and PRINT ARGS. The meaning of
PRINT_WHAT is:
@@ -533,6 +581,19 @@ print_frame_info (struct frame_info *fra

source_print = (print_what == SRC_LINE || print_what == SRC_AND_LOC);

+ /* If disassemble-next-line is set to auto or on and doesn't have
+ line message, output current instructions. */
+ if ((disassemble_next_line == disassemble_next_line_auto
+ || disassemble_next_line == disassemble_next_line_on)
+ && source_print && !sal.symtab)
+ {
+ struct gdb_disassembly_stub_args args;
+ args.how_many = 1;
+ args.low = get_frame_pc (frame);
+ args.high = get_frame_pc (frame) + 1;
+ catch_errors (gdb_disassembly_stub, &args, "", RETURN_MASK_ALL);
+ }
+
if (source_print && sal.symtab)
{
int done = 0;
@@ -569,6 +630,17 @@ print_frame_info (struct frame_info *fra
print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
}
}
+
+ /* If disassemble-next-line is set to on and there is line
+ messages, output assembly codes for next line. */
+ if (disassemble_next_line == disassemble_next_line_on)
+ {
+ struct gdb_disassembly_stub_args args;
+ args.how_many = -1;
+ args.low = get_frame_pc (frame);
+ args.high = sal.end;
+ catch_errors (gdb_disassembly_stub, &args, "", RETURN_MASK_ALL);
+ }
}

if (print_what != LOCATION)
@@ -2062,6 +2134,19 @@ Usage: func <name>\n"));
_("Show printing of non-scalar frame arguments"),
NULL, NULL, NULL, &setprintlist, &showprintlist);

+ add_setshow_enum_cmd ("disassemble-next-line", class_run,
+ disassemble_next_line_enum,
+ &disassemble_next_line, _("\
+Set debugger's willingness to use disassemble-next-line."), _("\
+Show debugger's willingness to use disassemble-next-line."), _("\
+If on, gdb will output the assembly codes of next line.\n\
+If off, gdb will not do it.\n\
+If auto (which is the default), gdb will output a assembly code\n\
+at current address if there is not line message."),
+ NULL,
+ show_disassemble_next_line,
+ &setlist, &showlist);
+
#if 0
add_cmd ("backtrace-limit", class_stack, set_backtrace_limit_command, _(\
"Specify maximum number of frames for \"backtrace\" to print by default."),