public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Frederic RISS <frederic.riss@st.com>
To: gdb@sources.redhat.com
Subject: MI mixed disassembly address range issue
Date: Thu, 01 Sep 2005 11:28:00 -0000	[thread overview]
Message-ID: <1125574080.9016.86.camel@crx549.cro.st.com> (raw)

Hello,

when using the -data-disassemble MI command with the -s and -e options
to specify the address range to disassemble, it's quit easy to break the
following assumption in disasm.c :

  /* Assume symtab is valid for whole PC range */
  symtab = find_pc_symtab (low);

If the low and high address' aren't recorded in the same symtab, we hit
this code in do_mixed_source_and_assembly :

  /* If we're on the last line, and it's part of the function,
     then we need to get the end pc in a special way.  */

  if (i == nlines - 1 && le[i].pc < high)
    {
      mle[newlines].line = le[i].line;
      mle[newlines].start_pc = le[i].pc;
      sal = find_pc_line (le[i].pc, 0);
      mle[newlines].end_pc = sal.end;
      newlines++;
    }

I tested this with the Dwarf2 debug format which introduces
'end-of-function' markers (ie lineentries with 0 as line number). When
reaching the end of the table, the above code introduces an entry with 0
line number in the 'lines to be dumped' array. 
The result is like that :

-data-disassemble -s 0x804859e -e 0x8048600 -- 1
^done,asm_insns=[src_and_asm_line={line="0",file="main.c",line_asm_insn=[]},
src_and_asm_line={line="1",file="main.c",line_asm_insn=[]},
<src_and_asm_line={line="x",file="main.c",line_asm_insn=[]},> [repeated for 0 <= x <= 109]
src_and_asm_line={line="108",file="main.c",line_asm_insn=[]},
src_and_asm_line={line="109",file="main.c",line_asm_insn=[{address="0x0804859e",
func-name="main",offset="375",inst="movl   $0x4,0xfffffff4(%ebp)"},
[ ... stripped correct output ]

As you see the lines 0-<line of start address> are output empty, which
seems like a bug. One obvious fix for this is to patch
do_mixed_source_and_assembly along the lines of :

--- disasm.c.old 2005-08-31 15:16:13.000000000 +0200
+++ disasm.c    2005-08-31 15:32:40.000000000 +0200
@@ -200,7 +200,7 @@
  /* If we're on the last line, and it's part of the function,
     then we need to get the end pc in a special way.  */

-  if (i == nlines - 1 && le[i].pc < high)
+  if (i == nlines - 1 && le[i].pc < high && le[i].line != 0)
     {
            mle[newlines].line = le[i].line;
            mle[newlines].start_pc = le[i].pc;


I don't know if all debug formats (or even Dwarf in all cases) will
output an end-marker at the end of the linetable, but if it's the case,
the offending code could be totally removed as we'll always have
le[nlines-1].line == 0.

Kind regards,
Fred.

                 reply	other threads:[~2005-09-01 11:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1125574080.9016.86.camel@crx549.cro.st.com \
    --to=frederic.riss@st.com \
    --cc=gdb@sources.redhat.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).