Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RE: [RFA] DLLs without debugging symbols (repost)
@ 2003-02-20 20:11 Zaretskii Eli
  2003-02-23 17:46 ` Raoul Gough
  0 siblings, 1 reply; 12+ messages in thread
From: Zaretskii Eli @ 2003-02-20 20:11 UTC (permalink / raw)
  To: Elena Zannoni, Raoul Gough; +Cc: gdb-patches


This message was scanned for viruses and other malicious code by PrivaWall.


This mail was sent from ELTA SYS LTD.


> From: Elena Zannoni [mailto:ezannoni@redhat.com] 
> Sent: Thursday, February 20, 2003 4:00 AM
> 
> The texinfo stuff should be approved by Eli. Mybe post it as a
> separate [RFA/doco] message, it will be more likely to be noticed.

Sorry, I did miss the original message.

The doco patch is approved, but please put "kernel32.dll" inside @file.

Also, please use "---" (three dashes in a row) instead of just "-" when
you want an em-dash in the manual.

Symbol names such as ``KERNEL32!CreateFileA'' should be in @code (and
without the quotes).

Instead of "(see @ref{Symbols})", please use "(@pxref{Symbols})".

Finally, I suggest some @cindex entry about symbol names in non-debug
DLLs somewhere in the text.  Users might look for this information in
the index.

Thanks!
 


This message is processed by the PrivaWall Email Security Server. 


^ permalink raw reply	[flat|nested] 12+ messages in thread
* [RFA] DLLs without debugging symbols (repost)
@ 2003-02-06 22:55 Raoul Gough
  2003-02-06 23:36 ` Christopher Faylor
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Raoul Gough @ 2003-02-06 22:55 UTC (permalink / raw)
  To: gdb-patches

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

Apparently my copyright assignment forms have now been processed, so
my patches for extracting minimal symbols from DLLs could now be
entered into CVS. This message includes up-to-date diffs with the
latest versions of the relevant files, as well as some documentation
that I've added to gdb.texinfo (basically, there's a new node under
the Cygwin Native node entitled "Non-debug DLL symbols" which explains
some of the tricks involved).

Regards,
Raoul Gough.

[-- Attachment #2: coffread.diff.txt --]
[-- Type: text/plain, Size: 880 bytes --]

Index: coffread.c
===================================================================
RCS file: /cvs/src/src/gdb/coffread.c,v
retrieving revision 1.33
diff -c -p -r1.33 coffread.c
*** coffread.c	4 Feb 2003 18:07:00 -0000	1.33
--- coffread.c	6 Feb 2003 19:39:27 -0000
***************
*** 45,50 ****
--- 45,52 ----
  #include "target.h"
  #include "gdb_assert.h"
  
+ #include "coff-pe-read.h"
+ 
  extern void _initialize_coffread (void);
  
  struct coff_symfile_info
*************** coff_symtab_read (long symtab_offset, un
*** 1084,1089 ****
--- 1086,1098 ----
  	  process_coff_symbol (cs, &main_aux, objfile);
  	  break;
  	}
+     }
+ 
+   if ((nsyms == 0) && (pe_file))
+     {
+       /* We've got no debugging symbols, but it's is a portable
+ 	 executable, so try to read the export table */
+       read_pe_exported_syms (objfile);
      }
  
    if (last_source_file)

[-- Attachment #3: Makefile.in.diff.txt --]
[-- Type: text/plain, Size: 3072 bytes --]

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.325
diff -c -p -r1.325 Makefile.in
*** Makefile.in	6 Feb 2003 05:30:16 -0000	1.325
--- Makefile.in	6 Feb 2003 19:39:49 -0000
*************** SFILES = ada-exp.y ada-lang.c ada-typepr
*** 511,517 ****
  	ax-general.c ax-gdb.c \
  	bcache.c blockframe.c breakpoint.c buildsym.c builtin-regs.c \
  	c-exp.y c-lang.c c-typeprint.c c-valprint.c \
! 	charset.c cli-out.c coffread.c complaints.c completer.c corefile.c \
  	cp-abi.c cp-support.c cp-valprint.c \
  	dbxread.c demangle.c disasm.c doublest.c \
  	dummy-frame.c dwarfread.c dwarf2read.c \
--- 511,518 ----
  	ax-general.c ax-gdb.c \
  	bcache.c blockframe.c breakpoint.c buildsym.c builtin-regs.c \
  	c-exp.y c-lang.c c-typeprint.c c-valprint.c \
! 	charset.c cli-out.c coffread.c coff-pe-read.c \
! 	complaints.c completer.c corefile.c \
  	cp-abi.c cp-support.c cp-valprint.c \
  	dbxread.c demangle.c disasm.c doublest.c \
  	dummy-frame.c dwarfread.c dwarf2read.c \
*************** call_cmds_h = call-cmds.h
*** 612,617 ****
--- 613,619 ----
  ch_lang_h = ch-lang.h
  cli_out_h = cli-out.h
  coff_solib_h = coff-solib.h
+ coff_pe_read_h = coff-pe-read.h
  command_h = command.h
  complaints_h = complaints.h
  completer_h = completer.h
*************** COMMON_OBS = version.o blockframe.o brea
*** 833,839 ****
  	kod.o kod-cisco.o \
  	gdb-events.o \
  	exec.o bcache.o objfiles.o minsyms.o maint.o demangle.o \
! 	dbxread.o coffread.o elfread.o \
  	dwarfread.o dwarf2read.o mipsread.o stabsread.o corefile.o \
  	c-lang.o f-lang.o \
  	ui-out.o cli-out.o \
--- 835,841 ----
  	kod.o kod-cisco.o \
  	gdb-events.o \
  	exec.o bcache.o objfiles.o minsyms.o maint.o demangle.o \
! 	dbxread.o coffread.o coff-pe-read.o elfread.o \
  	dwarfread.o dwarf2read.o mipsread.o stabsread.o corefile.o \
  	c-lang.o f-lang.o \
  	ui-out.o cli-out.o \
*************** coffread.o: coffread.c $(defs_h) $(symta
*** 1564,1570 ****
  	$(breakpoint_h) $(bfd_h) $(gdb_obstack_h) $(gdb_string_h) \
  	$(coff_internal_h) $(libcoff_h) $(symfile_h) $(objfiles_h) \
  	$(buildsym_h) $(gdb_stabs_h) $(stabsread_h) $(complaints_h) \
! 	$(target_h) $(gdb_assert_h)
  complaints.o: complaints.c $(defs_h) $(complaints_h) $(gdb_assert_h) \
  	$(command_h) $(gdbcmd_h)
  completer.o: completer.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(expression_h) \
--- 1566,1574 ----
  	$(breakpoint_h) $(bfd_h) $(gdb_obstack_h) $(gdb_string_h) \
  	$(coff_internal_h) $(libcoff_h) $(symfile_h) $(objfiles_h) \
  	$(buildsym_h) $(gdb_stabs_h) $(stabsread_h) $(complaints_h) \
! 	$(target_h) $(gdb_assert_h) $(coff_pe_read_h)
! coff-pe-read.o: coff-pe-read.c $(bfd_h) $(defs_h) $(symtab_h) \
! 	$(gdbtypes_h) $(symfile_h) $(objfiles_h) $(coff_pe_read_h)
  complaints.o: complaints.c $(defs_h) $(complaints_h) $(gdb_assert_h) \
  	$(command_h) $(gdbcmd_h)
  completer.o: completer.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(expression_h) \

[-- Attachment #4: coff-pe-read.h --]
[-- Type: application/octet-stream, Size: 1207 bytes --]

/* Interface to coff-pe-read.c (portable-executable-specific symbol reader).

   Copyright 2003 Free Software Foundation, Inc.

   This file is part of GDB.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Contributed by Raoul M. Gough (RaoulGough@yahoo.co.uk). */

#if !defined (COFF_PE_READ_H)
#define COFF_PE_READ_H

struct objfile;

/* Read the export table and convert it to minimal symbol table entries */
void read_pe_exported_syms (struct objfile *objfile);

#endif /* !defined (COFF_PE_READ_H) */

[-- Attachment #5: coff-pe-read.c --]
[-- Type: application/octet-stream, Size: 10412 bytes --]

/* Read the export table symbols from a portable executable and
   convert to internal format, for GDB. Used as a last resort if no
   debugging symbols recognized.

   Copyright 2003 Free Software Foundation, Inc.

   This file is part of GDB.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Contributed by Raoul M. Gough (RaoulGough@yahoo.co.uk). */

#include "coff-pe-read.h"

#include "bfd.h"

#include "defs.h"
#include "gdbtypes.h"

#include "symtab.h"
#include "symfile.h"
#include "objfiles.h"

/* Internal section information */

struct read_pe_section_data
{
  CORE_ADDR vma_offset;               /* Offset to loaded address of section.*/
  unsigned long rva_start;            /* Start offset within the pe. */
  unsigned long rva_end;              /* End offset within the pe. */
  enum minimal_symbol_type ms_type;   /* Type to assign symbols in section. */
};

#define PE_SECTION_INDEX_TEXT     0
#define PE_SECTION_INDEX_DATA     1
#define PE_SECTION_INDEX_BSS      2
#define PE_SECTION_TABLE_SIZE     3
#define PE_SECTION_INDEX_INVALID -1
\f
/* Get the index of the named section in our own array, which contains
   text, data and bss in that order. Return PE_SECTION_INDEX_INVALID
   if passed an unrecognised section name. */

static int
read_pe_section_index (const char *section_name)
{
  if (strcmp (section_name, ".text") == 0)
    {
      return PE_SECTION_INDEX_TEXT;
    }

  else if (strcmp (section_name, ".data") == 0)
    {
      return PE_SECTION_INDEX_DATA;
    }

  else if (strcmp (section_name, ".bss") == 0)
    {
      return PE_SECTION_INDEX_BSS;
    }

  else
    {
      return PE_SECTION_INDEX_INVALID;
    }
}

/* Record the virtual memory address of a section. */

static void
get_section_vmas (bfd *abfd, asection *sectp, void *context)
{
  struct read_pe_section_data *sections = context;
  int sectix = read_pe_section_index (sectp->name);

  if (sectix != PE_SECTION_INDEX_INVALID)
    {
      /* Data within the section start at rva_start in the pe and at
         bfd_get_section_vma() within memory. Store the offset. */

      sections[sectix].vma_offset
	= bfd_get_section_vma (abfd, sectp) - sections[sectix].rva_start;
    }
}
\f
/* Create a minimal symbol entry for an exported symbol. */

static void
add_pe_exported_sym (char *sym_name,
		     unsigned long func_rva,
		     const struct read_pe_section_data *section_data,
		     const char *dll_name,
		     struct objfile *objfile)
{
  /* Add the stored offset to get the loaded address of the symbol. */

  CORE_ADDR vma = func_rva + section_data->vma_offset;

  char *qualified_name = 0;
  int dll_name_len = strlen (dll_name);
  int count;

  /* Generate a (hopefully unique) qualified name using the first part
     of the dll name, e.g. KERNEL32!AddAtomA. This matches the style
     used by windbg from the "Microsoft Debugging Tools for Windows". */

  qualified_name = xmalloc (dll_name_len + strlen (sym_name) + 2);

  strncpy (qualified_name, dll_name, dll_name_len);
  qualified_name[dll_name_len] = '!';
  strcpy (qualified_name + dll_name_len + 1, sym_name);

  prim_record_minimal_symbol (qualified_name,
			      vma,
			      section_data->ms_type,
			      objfile);

  xfree (qualified_name);

  /* Enter the plain name as well, which might not be unique. */
  prim_record_minimal_symbol (sym_name,
			      vma,
			      section_data->ms_type,
			      objfile);
}

/* Truncate a dll_name at the first dot character. */

static void
read_pe_truncate_name (char *dll_name)
{
  while (*dll_name)
    {
      if ((*dll_name) == '.')
	{
	  *dll_name = '\0'; /* truncates and causes loop exit. */
	}

      else
	{
	  ++dll_name;
	}
    }
}
\f
/* Low-level support functions, direct from the ld module pe-dll.c. */
static unsigned int
pe_get16 (bfd *abfd, int where)
{
  unsigned char b[2];

  bfd_seek (abfd, (file_ptr) where, SEEK_SET);
  bfd_bread (b, (bfd_size_type) 2, abfd);
  return b[0] + (b[1] << 8);
}

static unsigned int
pe_get32 (bfd *abfd, int where)
{
  unsigned char b[4];

  bfd_seek (abfd, (file_ptr) where, SEEK_SET);
  bfd_bread (b, (bfd_size_type) 4, abfd);
  return b[0] + (b[1] << 8) + (b[2] << 16) + (b[3] << 24);
}

static unsigned int
pe_as32 (void *ptr)
{
  unsigned char *b = ptr;

  return b[0] + (b[1] << 8) + (b[2] << 16) + (b[3] << 24);
}
\f
/* Read the (non-debug) export symbol table from a portable
   executable. Code originally lifted from the ld function
   pe_implied_import_dll in pe-dll.c. */

void
read_pe_exported_syms (struct objfile *objfile)
{
  bfd *dll = objfile->obfd;
  unsigned long pe_header_offset, opthdr_ofs, num_entries, i;
  unsigned long export_rva, export_size, nsections, secptr, expptr;
  unsigned long exp_funcbase;
  unsigned char *expdata, *erva;
  unsigned long name_rvas, ordinals, nexp, ordbase;
  char *dll_name;

  /* Array elements are for text, data and bss in that order
     Initialization with start_rva > end_rva guarantees that
     unused sections won't be matched. */
  struct read_pe_section_data section_data[PE_SECTION_TABLE_SIZE]
    = { {0, 1, 0, mst_text},
	{0, 1, 0, mst_data},
	{0, 1, 0, mst_bss} };

  struct cleanup *back_to = 0;

  char const *target = bfd_get_target (objfile->obfd);

  if ((strcmp (target, "pe-i386") != 0) && (strcmp (target, "pei-i386") != 0))
    {
      /* This is not an i386 format file. Abort now, because the code
	 is untested on anything else. *FIXME* test on further
	 architectures and loosen or remove this test. */
      return;
    }

  /* Get pe_header, optional header and numbers of export entries.  */
  pe_header_offset = pe_get32 (dll, 0x3c);
  opthdr_ofs = pe_header_offset + 4 + 20;
  num_entries = pe_get32 (dll, opthdr_ofs + 92);

  if (num_entries < 1) /* No exports.  */
    {
      return;
    }

  export_rva = pe_get32 (dll, opthdr_ofs + 96);
  export_size = pe_get32 (dll, opthdr_ofs + 100);
  nsections = pe_get16 (dll, pe_header_offset + 4 + 2);
  secptr = (pe_header_offset + 4 + 20 +
	    pe_get16 (dll, pe_header_offset + 4 + 16));
  expptr = 0;

  /* Get the rva and size of the export section.  */ 
  for (i = 0; i < nsections; i++)
    {
      char sname[8];
      unsigned long secptr1 = secptr + 40 * i;
      unsigned long vaddr = pe_get32 (dll, secptr1 + 12);
      unsigned long vsize = pe_get32 (dll, secptr1 + 16);
      unsigned long fptr = pe_get32 (dll, secptr1 + 20);

      bfd_seek (dll, (file_ptr) secptr1, SEEK_SET);
      bfd_bread (sname, (bfd_size_type) 8, dll);

      if (vaddr <= export_rva && vaddr + vsize > export_rva)
	{
	  expptr = fptr + (export_rva - vaddr);
	  if (export_rva + export_size > vaddr + vsize)
	    export_size = vsize - (export_rva - vaddr);
	  break;
	}
    }

  if (export_size == 0)
    {
      /* Empty export table. */
      return;
    }

  /* Scan sections and store the base and size of the relevant sections. */
  for (i = 0; i < nsections; i++)
    {
      unsigned long secptr1 = secptr + 40 * i;
      unsigned long vsize = pe_get32 (dll, secptr1 + 8);
      unsigned long vaddr = pe_get32 (dll, secptr1 + 12);
      unsigned long flags = pe_get32 (dll, secptr1 + 36);
      char sec_name[9];
      int sectix;

      sec_name[8] = '\0';
      bfd_seek (dll, (file_ptr) secptr1 + 0, SEEK_SET);
      bfd_bread (sec_name, (bfd_size_type) 8, dll);

      sectix = read_pe_section_index (sec_name);

      if (sectix != PE_SECTION_INDEX_INVALID)
	{
	  section_data[sectix].rva_start = vaddr;
	  section_data[sectix].rva_end = vaddr + vsize;
	}
    }

  expdata = (unsigned char *) xmalloc (export_size);
  back_to = make_cleanup (xfree, expdata);

  bfd_seek (dll, (file_ptr) expptr, SEEK_SET);
  bfd_bread (expdata, (bfd_size_type) export_size, dll);
  erva = expdata - export_rva;

  nexp = pe_as32 (expdata + 24);
  name_rvas = pe_as32 (expdata + 32);
  ordinals = pe_as32 (expdata + 36);
  ordbase = pe_as32 (expdata + 16);
  exp_funcbase = pe_as32 (expdata + 28);

  /* Use internal dll name instead of full pathname. */
  dll_name = pe_as32 (expdata + 12) + erva;

  bfd_map_over_sections (dll, get_section_vmas, section_data);

  /* Adjust the vma_offsets in case this PE got relocated. This
     assumes that *all* sections share the same relocation offset
     as the text section. */
  for (i = 0; i < PE_SECTION_TABLE_SIZE; i++)
    {
      section_data[i].vma_offset
	+= ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
    }

  printf_filtered ("Minimal symbols from %s...", dll_name);
  wrap_here ("");

  /* Truncate name at first dot. Should maybe also convert to all
     lower case for convenience on Windows. */
  read_pe_truncate_name (dll_name);

  /* Iterate through the list of symbols.  */
  for (i = 0; i < nexp; i++)
    {
      /* Pointer to the names vector.  */
      unsigned long name_rva = pe_as32 (erva + name_rvas + i * 4);

      /* Pointer to the function address vector.  */ 
      unsigned long func_rva = pe_as32 (erva + exp_funcbase + i * 4);

      /* Find this symbol's section in our own array. */
      int sectix = 0;

      for (sectix = 0; sectix < PE_SECTION_TABLE_SIZE; ++sectix)
	{
	  if ((func_rva >= section_data[sectix].rva_start)
	      && (func_rva < section_data[sectix].rva_end))
	    {
	      add_pe_exported_sym (erva + name_rva,
				   func_rva,
				   section_data + sectix,
				   dll_name,
				   objfile);
	      break;
	    }
	}
    }

  /* discard expdata. */
  do_cleanups (back_to);
}




[-- Attachment #6: ChangeLog_entry.txt --]
[-- Type: text/plain, Size: 506 bytes --]

2003-02-06  Raoul Gough  <RaoulGough@yahoo.co.uk>

	* coff-pe-read.c: New file - support reading of minimal symbols
	from a portable executable using the export table.
	* coff-pe-read.h: New file
	* coffread.c: #include coff-pe-read.h
	(coff_symtab_read): call read_pe_exported_syms iff no recognized
	debugging symbols found.
	* Makefile.in (SFILES): add coff-pe-read.o
	(coff_pe_read_h): define
	(COMMON_OBS): add coff-pe-read.o
	(coffread.o): add coff_pe_read_h dependency
	(coff-pe-read.o): New target

[-- Attachment #7: doc_changelog_entry.txt --]
[-- Type: text/plain, Size: 232 bytes --]

2003-02-06  Raoul Gough  <RaoulGough@yahoo.co.uk>

	* gdb.texinfo (Cygwin Native): Links to Non-debug DLL symbols.
	(Non-debug DLL symbols): New node, describing the minimal
	symbols loaded from DLLs without real debugging symbols.

[-- Attachment #8: gdb.texinfo.diff.txt --]
[-- Type: text/plain, Size: 6381 bytes --]

Index: gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.147
diff -c -p -r1.147 gdb.texinfo
*** gdb.texinfo	4 Feb 2003 22:52:51 -0000	1.147
--- gdb.texinfo	6 Feb 2003 22:54:28 -0000
*************** This command is supported only with some
*** 11142,11150 ****
  @cindex native Cygwin debugging
  @cindex Cygwin-specific commands
  
! @value{GDBN} supports native debugging of MS Windows programs, and
! defines a few commands specific to the Cygwin port.  This
! subsection describes those commands.
  
  @table @code
  @kindex info w32
--- 11142,11153 ----
  @cindex native Cygwin debugging
  @cindex Cygwin-specific commands
  
! @value{GDBN} supports native debugging of MS Windows programs, including
! DLLs with and without symbolic debugging information. There are various
! additional Cygwin-specific commands, described in this subsection.  The
! subsubsection @ref{Non-debug DLL symbols} describes working with DLLs
! that have no debugging symbols.
! 
  
  @table @code
  @kindex info w32
*************** via a shell or directly (default value i
*** 11221,11226 ****
--- 11224,11350 ----
  Displays if the debuggee will be started with a shell.
  
  @end table
+ 
+ @menu
+ * Non-debug DLL symbols::  Support for DLLs without debugging symbols
+ @end menu
+ 
+ @node Non-debug DLL symbols
+ @subsubsection Support for DLLs without debugging symbols
+ @cindex DLLs with no debugging symbols
+ 
+ Very often on windows, some of the DLLs that your program relies on do
+ not include symbolic debugging information (for example,
+ kernel32.dll). When @value{GDBN} doesn't recognize any debugging symbols
+ in a DLL, it relies on the minimal amount of symbolic information
+ contained in the DLL's export table. This subsubsection describes
+ working with such symbols, known internally to @value{GDBN} as ``minimal
+ symbols''.
+ 
+ Note that before the debugged program has started execution, no DLLs
+ will have been loaded. The easiest way around this problem is simply to
+ start the program - either by setting a breakpoint or letting the
+ program run once to completion. It is also possible to force
+ @value{GDBN} to load a particular DLL before starting the executable -
+ see the shared library information in @ref{Files} or the
+ @code{dll-symbols} command in @ref{Cygwin Native}. Currently, explicitly
+ loading symbols from a DLL with no debugging information will cause the
+ same symbols to be duplicated in @value{GDBN}'s symbol table, which may
+ adversely affect symbol lookup performance.
+ 
+ @subsubsection DLL name prefixes
+ 
+ In keeping with the naming conventions used by the Microsoft debugging
+ tools, DLL export symbols are made available with a prefix based on the
+ DLL name, for instance ``KERNEL32!CreateFileA''.  The plain name is also
+ entered into the symbol table, so ``CreateFileA'' is often
+ sufficient. In some cases there will be name clashes within a program
+ (particularly if the executable itself includes full debugging symbols)
+ necessitating the use of the fully qualified name. Use single-quotes
+ around the name to avoid the exclamation mark (``!'')  being interpreted
+ as a language operator.
+ 
+ Note that the internal name of the DLL may be all upper-case, even
+ though the file name of the DLL is lower-case, or vice-versa. Since
+ symbols within @value{GDBN} are @emph{case-sensitive} this may cause
+ some confusion. If in doubt, try the @code{info functions} and
+ @code{info variables} commands or even @code{maint print msymbols} (see
+ @ref{Symbols}). Here's an example:
+ 
+ @smallexample
+ (gdb) info function CreateFileA
+ All functions matching regular expression "CreateFileA":
+ 
+ Non-debugging symbols:
+ 0x77e885f4  CreateFileA
+ 0x77e885f4  KERNEL32!CreateFileA
+ @end smallexample
+ 
+ @smallexample
+ (gdb) info function !
+ All functions matching regular expression "!":
+ 
+ Non-debugging symbols:
+ 0x6100114c  cygwin1!__assert
+ 0x61004034  cygwin1!_dll_crt0@@0
+ 0x61004240  cygwin1!dll_crt0(per_process *)
+ [etc...]
+ @end smallexample
+ 
+ @subsubsection Working with minimal symbols
+ 
+ Symbols extracted from a DLL's export table do not contain very much
+ type information. All that @value{GDBN} can do is guess whether a symbol
+ refers to a function or variable depending on the linker section that
+ contains the symbol. Also note that the actual contents of the memory
+ contained in a DLL are not available unless the program is running. This
+ means that you cannot examine the contents of a variable or disassemble
+ a function within a DLL without a running program.
+ 
+ Variables are generally treated as pointers and dereferenced
+ automatically. For this reason, it is often necessary to prefix a
+ variable name with an ampersand (``&'') and provide explicit type
+ information in the command. Here's an example of the type of problem:
+ 
+ @smallexample
+ (gdb) print 'cygwin1!__argv'
+ $1 = 268572168
+ @end smallexample
+ 
+ @smallexample
+ (gdb) x 'cygwin1!__argv'
+ 0x10021610:      "\230y\""
+ @end smallexample
+ 
+ And two possible solutions:
+ 
+ @smallexample
+ (gdb) print ((char **)'cygwin1!__argv')[0]
+ $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
+ @end smallexample
+ 
+ @smallexample
+ (gdb) x/2x &'cygwin1!__argv'
+ 0x610c0aa8 <cygwin1!__argv>:    0x10021608      0x00000000
+ (gdb) x/x 0x10021608
+ 0x10021608:     0x0022fd98
+ (gdb) x/s 0x0022fd98
+ 0x22fd98:        "/cygdrive/c/mydirectory/myprogram"
+ @end smallexample
+ 
+ Setting a break point within a DLL is possible even before the program
+ starts execution. However, under these circumstances, @value{GDBN} can't
+ examine the initial instructions of the function in order to skip the
+ function's frame set-up code. You can work around this by using ``*&''
+ to set the breakpoint at a raw memory address:
+ 
+ @smallexample
+ (gdb) break *&'python22!PyOS_Readline'
+ Breakpoint 1 at 0x1e04eff0
+ @end smallexample
+ 
+ The author of these extensions is not entirely convinced that setting a
+ break point within a shared DLL like kernel32.dll is completely safe.
  
  @node Embedded OS
  @section Embedded Operating Systems

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2003-02-23 19:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-20 20:11 [RFA] DLLs without debugging symbols (repost) Zaretskii Eli
2003-02-23 17:46 ` Raoul Gough
2003-02-23 17:53   ` Christopher Faylor
2003-02-23 19:09     ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2003-02-06 22:55 Raoul Gough
2003-02-06 23:36 ` Christopher Faylor
2003-02-11 21:46   ` Raoul Gough
2003-02-11 21:52     ` Elena Zannoni
2003-02-20  1:55 ` Elena Zannoni
2003-02-20  2:18 ` Elena Zannoni
2003-02-20  3:14   ` Christopher Faylor
2003-02-23 17:48     ` Raoul Gough

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox