RFC: Moving disassembler_command to cli land and using newer disassembler code

Fernando Nasser fnasser@redhat.com
Thu Nov 7 19:23:00 GMT 2002


As Daniel and Elena liked the new output, I will just change the test 
pattern and check this in.

Thanks for the comments.

Fernando

Fernando Nasser wrote:
> As soon as I can solve the small output differences between what is 
> printed by the old code and what the new one prints I will be doing the 
> following code migration, removing one more cli command from the library 
> and making it use the disassembler code in disasm.c.
> 
> This will allow us to have an option to have disassembler in mixed 
> source and assembler mode in the CLI as well.  But that is for when I 
> come back.
> 
> The differences in the output are the "+0" in symbolic addresses (which 
> I've mentioned in a separate message) and the leading zeros in the 
> numeric addresses (see printouts below).  The old code used 
> print_address_numeric() and the new code uses ui_out_field_core_addr().  
> W.r.t. this leading zero(s), I am not sure if we should print it or not 
> (I can just update the test file).RFC:
> 
> Output with old code:
> disassem foostatic
> Dump of assembler code for function foostatic:
> 0x8048153 <foostatic>:  push   %ebp
> 0x8048154 <foostatic+1>:        mov    %esp,%ebp
> 0x8048156 <foostatic+3>:        pop    %ebp
> 0x8048157 <foostatic+4>:        ret
> End of assembler dump.
> (gdb) PASS: gdb.asm/asm-source.exp: look at static function
> 
> Output with new code:
> disassem foostatic^M
> Dump of assembler code for function foostatic:^M
> 0x08048153 <foostatic+0>:       push   %ebp^M
> 0x08048154 <foostatic+1>:       mov    %esp,%ebp^M
> 0x08048156 <foostatic+3>:       pop    %ebp^M
> 0x08048157 <foostatic+4>:       ret    ^M
> End of assembler dump.^M
> (gdb) FAIL: gdb.asm/asm-source.exp: look at static function
> 
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> Index: printcmd.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/printcmd.c,v
> retrieving revision 1.43
> diff -c -p -r1.43 printcmd.c
> *** printcmd.c	19 Sep 2002 03:58:41 -0000	1.43
> --- printcmd.c	30 Sep 2002 21:13:12 -0000
> ***************
> *** 41,46 ****
> --- 41,47 ----
>   #include "completer.h"		/* for completion functions */
>   #include "ui-out.h"
>   #include "gdb_assert.h"
> + #include "disasm.h"
>   
>   extern int asm_demangle;	/* Whether to demangle syms in asm printouts */
>   extern int addressprint;	/* Whether to print hex addresses in HLL " */
> *************** static void enable_display (char *, int)
> *** 136,143 ****
>   
>   static void disable_display_command (char *, int);
>   
> - static void disassemble_command (char *, int);
> - 
>   static void printf_command (char *, int);
>   
>   static void print_frame_nameless_args (struct frame_info *, long,
> --- 137,142 ----
> *************** printf_command (char *arg, int from_tty)
> *** 2260,2373 ****
>     }
>     do_cleanups (old_cleanups);
>   }
> - 
> - /* Dump a specified section of assembly code.  With no command line
> -    arguments, this command will dump the assembly code for the
> -    function surrounding the pc value in the selected frame.  With one
> -    argument, it will dump the assembly code surrounding that pc value.
> -    Two arguments are interpeted as bounds within which to dump
> -    assembly.  */
> - 
> - /* ARGSUSED */
> - static void
> - disassemble_command (char *arg, int from_tty)
> - {
> -   CORE_ADDR low, high;
> -   char *name;
> -   CORE_ADDR pc, pc_masked;
> -   char *space_index;
> - #if 0
> -   asection *section;
> - #endif
> - 
> -   name = NULL;
> -   if (!arg)
> -     {
> -       if (!selected_frame)
> - 	error ("No frame selected.\n");
> - 
> -       pc = get_frame_pc (selected_frame);
> -       if (find_pc_partial_function (pc, &name, &low, &high) == 0)
> - 	error ("No function contains program counter for selected frame.\n");
> - #if defined(TUI)
> -       else if (tui_version)
> - 	low = tuiGetLowDisassemblyAddress (low, pc);
> - #endif
> -       low += FUNCTION_START_OFFSET;
> -     }
> -   else if (!(space_index = (char *) strchr (arg, ' ')))
> -     {
> -       /* One argument.  */
> -       pc = parse_and_eval_address (arg);
> -       if (find_pc_partial_function (pc, &name, &low, &high) == 0)
> - 	error ("No function contains specified address.\n");
> - #if defined(TUI)
> -       else if (tui_version)
> - 	low = tuiGetLowDisassemblyAddress (low, pc);
> - #endif
> -       low += FUNCTION_START_OFFSET;
> -     }
> -   else
> -     {
> -       /* Two arguments.  */
> -       *space_index = '\0';
> -       low = parse_and_eval_address (arg);
> -       high = parse_and_eval_address (space_index + 1);
> -     }
> - 
> - #if defined(TUI)
> -   if (!tui_is_window_visible (DISASSEM_WIN))
> - #endif
> -     {
> -       printf_filtered ("Dump of assembler code ");
> -       if (name != NULL)
> - 	{
> - 	  printf_filtered ("for function %s:\n", name);
> - 	}
> -       else
> - 	{
> - 	  printf_filtered ("from ");
> - 	  print_address_numeric (low, 1, gdb_stdout);
> - 	  printf_filtered (" to ");
> - 	  print_address_numeric (high, 1, gdb_stdout);
> - 	  printf_filtered (":\n");
> - 	}
> - 
> -       /* Dump the specified range.  */
> -       pc = low;
> - 
> - #ifdef GDB_TARGET_MASK_DISAS_PC
> -       pc_masked = GDB_TARGET_MASK_DISAS_PC (pc);
> - #else
> -       pc_masked = pc;
> - #endif
> - 
> -       while (pc_masked < high)
> - 	{
> - 	  QUIT;
> - 	  print_address (pc_masked, gdb_stdout);
> - 	  printf_filtered (":\t");
> - 	  /* We often wrap here if there are long symbolic names.  */
> - 	  wrap_here ("    ");
> - 	  pc += print_insn (pc, gdb_stdout);
> - 	  printf_filtered ("\n");
> - 
> - #ifdef GDB_TARGET_MASK_DISAS_PC
> - 	  pc_masked = GDB_TARGET_MASK_DISAS_PC (pc);
> - #else
> - 	  pc_masked = pc;
> - #endif
> - 	}
> -       printf_filtered ("End of assembler dump.\n");
> -       gdb_flush (gdb_stdout);
> -     }
> - #if defined(TUI)
> -   else
> -     {
> -       tui_show_assembly (low);
> -     }
> - #endif
> - }
>   
>   /* Print the instruction at address MEMADDR in debugged memory,
>      on STREAM.  Returns length of the instruction, in bytes.  */
> --- 2259,2264 ----
> *************** according to the format.\n\n\
> *** 2416,2430 ****
>   Defaults for format and size letters are those previously used.\n\
>   Default count is 1.  Default address is following last thing printed\n\
>   with this command or \"print\".", NULL));
> - 
> -   c = add_com ("disassemble", class_vars, disassemble_command,
> - 	       "Disassemble a specified section of memory.\n\
> - Default is the function surrounding the pc of the selected frame.\n\
> - With a single argument, the function surrounding that address is dumped.\n\
> - Two arguments are taken as a range of memory to dump.");
> -   set_cmd_completer (c, location_completer);
> -   if (xdb_commands)
> -     add_com_alias ("va", "disassemble", class_xdb, 0);
>   
>   #if 0
>     add_com ("whereis", class_vars, whereis_command,
> --- 2307,2312 ----
> Index: cli/cli-cmds.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/cli/cli-cmds.c,v
> retrieving revision 1.22
> diff -c -p -r1.22 cli-cmds.c
> *** cli/cli-cmds.c	22 Sep 2002 22:18:41 -0000	1.22
> --- cli/cli-cmds.c	30 Sep 2002 21:13:13 -0000
> ***************
> *** 27,36 ****
> --- 27,39 ----
>   #include "gdb_string.h"
>   #include "linespec.h"
>   #include "expression.h"
> + #include "frame.h"
> + #include "value.h"
>   #include "language.h"
>   #include "filenames.h"		/* for DOSish file names */
>   #include "objfiles.h"
>   #include "source.h"
> + #include "disasm.h"
>   
>   #include "ui-out.h"
>   
> *************** list_command (char *arg, int from_tty)
> *** 819,824 ****
> --- 822,913 ----
>   			0);
>   }
>   
> + /* Dump a specified section of assembly code.  With no command line
> +    arguments, this command will dump the assembly code for the
> +    function surrounding the pc value in the selected frame.  With one
> +    argument, it will dump the assembly code surrounding that pc value.
> +    Two arguments are interpeted as bounds within which to dump
> +    assembly.  */
> + 
> + /* ARGSUSED */
> + static void
> + disassemble_command (char *arg, int from_tty)
> + {
> +   CORE_ADDR low, high;
> +   char *name;
> +   CORE_ADDR pc, pc_masked;
> +   char *space_index;
> + #if 0
> +   asection *section;
> + #endif
> + 
> +   name = NULL;
> +   if (!arg)
> +     {
> +       if (!selected_frame)
> + 	error ("No frame selected.\n");
> + 
> +       pc = get_frame_pc (selected_frame);
> +       if (find_pc_partial_function (pc, &name, &low, &high) == 0)
> + 	error ("No function contains program counter for selected frame.\n");
> + #if defined(TUI)
> +       else if (tui_version)
> + 	low = tuiGetLowDisassemblyAddress (low, pc);
> + #endif
> +       low += FUNCTION_START_OFFSET;
> +     }
> +   else if (!(space_index = (char *) strchr (arg, ' ')))
> +     {
> +       /* One argument.  */
> +       pc = parse_and_eval_address (arg);
> +       if (find_pc_partial_function (pc, &name, &low, &high) == 0)
> + 	error ("No function contains specified address.\n");
> + #if defined(TUI)
> +       else if (tui_version)
> + 	low = tuiGetLowDisassemblyAddress (low, pc);
> + #endif
> +       low += FUNCTION_START_OFFSET;
> +     }
> +   else
> +     {
> +       /* Two arguments.  */
> +       *space_index = '\0';
> +       low = parse_and_eval_address (arg);
> +       high = parse_and_eval_address (space_index + 1);
> +     }
> + 
> + #if defined(TUI)
> +   if (!tui_is_window_visible (DISASSEM_WIN))
> + #endif
> +     {
> +       printf_filtered ("Dump of assembler code ");
> +       if (name != NULL)
> + 	{
> + 	  printf_filtered ("for function %s:\n", name);
> + 	}
> +       else
> + 	{
> + 	  printf_filtered ("from ");
> + 	  print_address_numeric (low, 1, gdb_stdout);
> + 	  printf_filtered (" to ");
> + 	  print_address_numeric (high, 1, gdb_stdout);
> + 	  printf_filtered (":\n");
> + 	}
> + 
> +       /* Dump the specified range.  */
> +       gdb_disassembly (uiout, 0, 0, 0, -1, low, high);
> + 
> +       printf_filtered ("End of assembler dump.\n");
> +       gdb_flush (gdb_stdout);
> +     }
> + #if defined(TUI)
> +   else
> +     {
> +       tui_show_assembly (low);
> +     }
> + #endif
> + }
> + 
>   static void
>   make_command (char *arg, int from_tty)
>   {
> *************** With two args if one is empty it stands 
> *** 1157,1162 ****
> --- 1246,1259 ----
>     if (dbx_commands)
>       add_com_alias ("file", "list", class_files, 1);
>   
> +   c = add_com ("disassemble", class_vars, disassemble_command,
> + 	       "Disassemble a specified section of memory.\n\
> + Default is the function surrounding the pc of the selected frame.\n\
> + With a single argument, the function surrounding that address is dumped.\n\
> + Two arguments are taken as a range of memory to dump.");
> +   set_cmd_completer (c, location_completer);
> +   if (xdb_commands)
> +     add_com_alias ("va", "disassemble", class_xdb, 0);
>   
>     /* NOTE: cagney/2000-03-20: Being able to enter ``(gdb) !ls'' would
>        be a really useful feature.  Unfortunately, the below wont do


-- 
Fernando Nasser
Red Hat Canada Ltd.                     E-Mail:  fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario   M4P 2C9



More information about the Gdb-patches mailing list