Re: [RFC] disassemble-next-line

teawater
2009-03-12T23:56:12Z

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

Hi guys,

I make a new patch according to your comments.
If you think it's OK. I will make the patch for doc.

Thanks,
Hui

On Wed, Mar 11, 2009 at 11:16, teawater <teawater@gmail.com> wrote:
> Hi guys,
>
> On Mon, Mar 9, 2009 at 23:26, Tom Tromey <tromey@redhat.com> wrote:
>>>>>>> "teawater" == teawater  <teawater@gmail.com> writes:
>>
>> teawater> This is the patch for the function to output assembly codes
>> teawater> for next line.
>>
>> teawater> +/* If ON, GDB will output the assembly codes of next line.
>> teawater> +   If OFF, GDB will not do it.
>> teawater> +   doesn't support it, GDB will instead use the traditional
>>
>> I think this third line should be removed.
>
> OK. I will remove it.
>
>>
>> teawater> +/* Show assembly codes; stub for catch_errors.  */
>> teawater> +
>> teawater> +struct gdb_disassembly_stub_args
>> teawater> +{
>> teawater> +  int how_many;
>> teawater> +  CORE_ADDR low;
>> teawater> +  CORE_ADDR high;
>> teawater> +};
>> teawater> +
>> teawater> +static int
>> teawater> +gdb_disassembly_stub (void *args)
>> teawater> +{
>> teawater> +  struct gdb_disassembly_stub_args *p = args;
>> teawater> +  gdb_disassembly (uiout, 0, 0, 0, p->how_many, p->low, p->high);
>> teawater> +  return 0;
>>
>> IMO, in this case it would be shorter, and clearer, to use TRY_CATCH
>> at the call site rather than catch_errors.  What do you think?
>
> OK.  I will change it to TRY_CATCH.
>
>>
>> teawater> +  /* If disassemble-next-line is set to auto or on and doesn't have
>> teawater> +     line message, output current instructions.  */
>>
>> "a line message"
>>
>> teawater> +      /* If disassemble-next-line is set to on and there is line
>> teawater> +         messages, output assembly codes for next line.  */
>>
>> "there are line messages"
>
> I will change it.
>
>>
>> teawater> +  add_setshow_enum_cmd ("disassemble-next-line", class_run,
>> teawater> +                     disassemble_next_line_enum,
>> teawater> +                     &disassemble_next_line, _("\
>> teawater> +Set debugger's willingness to use disassemble-next-line."), _("\
>>
>> This text seems circular.
>> Instead it should briefly describe what the option does.
>>
>> teawater> +Show debugger's willingness to use disassemble-next-line."), _("\
>> teawater> +If on, gdb will output the assembly codes of next line.\n\
>>
>> This also reads strangely, but I don't have a suggestion for what it
>> ought to say.  I think it should at least say when the assembly will
>> be displayed.  "assembly codes" in particular sounds odd to me.
>
> I think Doug's idea is better:
> If ON, GDB will disassemble the next source line when execution stops.
> If the next source line cannot be ascertained, the next instruction
> will be disassembled instead.
>
>>
>> teawater> +If auto (which is the default), gdb will output a assembly code\n\
>> teawater> +at current address if there is not line message."),
>>
>> "at the current address"
>
> I will change it.
>
>>
>> The line message bit could use rewording as well; at least s/not/no/.
>>
>
> About line message.
> struct symtab_and_line
> {
>  struct symtab *symtab;
>  struct obj_section *section;
>  /* Line number.  Line numbers start at 1 and proceed through symtab->nlines.
>     0 is never a valid line number; it is used to indicate that line number
>     information is not available.  */
>  int line;
>
>  CORE_ADDR pc;
>  CORE_ADDR end;
>  int explicit_pc;
>  int explicit_line;
> };
> It don't have comment name.
> What about change it to "line debug message"?
>
>
> Thanks for your help.
> Hui
>

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

---
stack.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 89 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,69 @@ 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 disassemble the next source line when execution
+ stops.
+ If AUTO (which is the default) or the next source line cannot be
+ ascertained, the next instruction will be disassembled instead. */
+
+static const char *disassemble_next_line = disassemble_next_line_auto;
+
+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 void
+gdb_disassembly_stub (void *args)
+{
+ struct gdb_disassembly_stub_args *p = args;
+ gdb_disassembly (uiout, 0, 0, p->how_many, p->low, p->high);
+}
+
+/* Use TRY_CATCH to catch the exception from the gdb_disassembly
+ because it will be broken by filter sometime. */
+
+static void
+do_gdb_disassembly (int how_many, CORE_ADDR low, CORE_ADDR high)
+{
+ volatile struct gdb_exception exception;
+ struct gdb_disassembly_stub_args args;
+
+ args.how_many = how_many;
+ args.low = low;
+ args.high = high;
+ TRY_CATCH (exception, RETURN_MASK_ALL)
+ {
+ gdb_disassembly_stub (&args);
+ }
+}
+
/* 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 +597,13 @@ 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
+ the line debug messages for $pc, output current instructions. */
+ if ((disassemble_next_line == disassemble_next_line_auto
+ || disassemble_next_line == disassemble_next_line_on)
+ && source_print && !sal.symtab)
+ do_gdb_disassembly (1, get_frame_pc (frame), get_frame_pc (frame) + 1);
+
if (source_print && sal.symtab)
{
int done = 0;
@@ -569,6 +640,11 @@ 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)
+ do_gdb_disassembly (-1, get_frame_pc (frame), sal.end);
}

if (print_what != LOCATION)
@@ -2062,6 +2138,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 disassemble the next source line when execution\n\
+stops.\n\
+If AUTO (which is the default) or the next source line cannot be\n\
+ascertained, the next instruction will be disassembled instead."),
+ 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."),