This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: The problem with stabs and sign extension
On Wed, Aug 08, 2001 at 04:14:21PM -0700, H . J . Lu wrote:
> On Wed, Aug 08, 2001 at 02:12:07PM -0700, Daniel Jacobowitz wrote:
> > The problem seems, to my inexperienced eye, to be in stabsread.c:
> >
> > #define INTERNALIZE_SYMBOL(intern, extern, abfd) \
> > { \
> > (intern).n_type = bfd_h_get_8 (abfd, (extern)->e_type); \
> > (intern).n_strx = bfd_h_get_32 (abfd, (extern)->e_strx); \
> > (intern).n_desc = bfd_h_get_16 (abfd, (extern)->e_desc); \
> > (intern).n_value = bfd_h_get_32 (abfd, (extern)->e_value); \
> > }
> >
> > n_value is a CORE_ADDR. bfd_h_get_32 returns a bfd_vma, without doing sign
> > extension. For MIPS, we want sign extension to have happened here. Right?
> > It does if we're reading mdebug in (because ECOFF_SIGNED_32 is defined in
> > BFD).
> >
> > On the other hand, I'm sure other targets don't want sign extension here.
> > How should we handle this?
>
With this patch, I can do
# gdb vmlinux
...
(gdb) print printk
$1 = {int (char *)} 0x8011c5b0 <printk>
(gdb) list printk
250 printk.c: No such file or directory.
in printk.c
H.J.
----
2001-08-08 H.J. Lu (hjl@gnu.org)
* dbxread.c (COERCE32): New.
(SWAP_SYMBOL): Removed.
(INTERNALIZE_SYMBOL): Check sign extended vma.
(read_ofile_symtab): Set text_offset with COERCE32.
--- gdb/dbxread.c.vma Fri Jul 13 12:12:34 2001
+++ gdb/dbxread.c Wed Aug 8 16:49:09 2001
@@ -109,6 +109,10 @@ struct symloc
#define SYMBOL_OFFSET(p) (SYMLOC(p)->symbol_offset)
#define STRING_OFFSET(p) (SYMLOC(p)->string_offset)
#define FILE_STRING_OFFSET(p) (SYMLOC(p)->file_string_offset)
+
+/* Sign extension to bfd_signed_vma. */
+#define COERCE32(x) \
+ ((bfd_signed_vma) (long) (((unsigned long) (x) ^ 0x80000000) - 0x80000000))
/* Remember what we deduced to be the source language of this psymtab. */
@@ -946,22 +950,15 @@ fill_symbuf (bfd *sym_bfd)
symbuf_read += nbytes;
}
-#define SWAP_SYMBOL(symp, abfd) \
- { \
- (symp)->n_strx = bfd_h_get_32(abfd, \
- (unsigned char *)&(symp)->n_strx); \
- (symp)->n_desc = bfd_h_get_16 (abfd, \
- (unsigned char *)&(symp)->n_desc); \
- (symp)->n_value = bfd_h_get_32 (abfd, \
- (unsigned char *)&(symp)->n_value); \
- }
-
#define INTERNALIZE_SYMBOL(intern, extern, abfd) \
{ \
(intern).n_type = bfd_h_get_8 (abfd, (extern)->e_type); \
(intern).n_strx = bfd_h_get_32 (abfd, (extern)->e_strx); \
(intern).n_desc = bfd_h_get_16 (abfd, (extern)->e_desc); \
- (intern).n_value = bfd_h_get_32 (abfd, (extern)->e_value); \
+ if (bfd_get_sign_extend_vma (abfd)) \
+ (intern).n_value = bfd_h_get_signed_32 (abfd, (extern)->e_value); \
+ else \
+ (intern).n_value = bfd_h_get_32 (abfd, (extern)->e_value); \
}
/* Invariant: The symbol pointed to by symbuf_idx is the first one
@@ -1687,7 +1684,7 @@ read_ofile_symtab (struct partial_symtab
objfile = pst->objfile;
sym_offset = LDSYMOFF (pst);
sym_size = LDSYMLEN (pst);
- text_offset = pst->textlow;
+ text_offset = COERCE32 (pst->textlow);
text_size = pst->texthigh - pst->textlow;
/* This cannot be simply objfile->section_offsets because of
elfstab_offset_sections() which initializes the psymtab section