public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Symbol can't be found unless type 'tab'
@ 2012-09-10 12:52 Yao Qi
  2012-09-10 13:18 ` Jan Kratochvil
  0 siblings, 1 reply; 8+ messages in thread
From: Yao Qi @ 2012-09-10 12:52 UTC (permalink / raw)
  To: gdb

Hi,
I am trying to create a piece of fake dwarf information that a 8-byte 
variable 'i' occupies two registers, as below, and it seems right to me.

Contents of the .debug_info section:

   Compilation Unit @ offset 0x0:
    Length:        0x34 (32-bit)
    Version:       2
    Abbrev Offset: 0
    Pointer Size:  4
  <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
     <c>   DW_AT_name        : set-reg.c
     <16>   DW_AT_producer    : GNU C 3.3.3
     <22>   DW_AT_language    : 2        (non-ANSI C)
  <1><23>: Abbrev Number: 2 (DW_TAG_base_type)
     <24>   DW_AT_name        : 8byte
     <2a>   DW_AT_byte_size   : 8
     <2b>   DW_AT_encoding    : 7        (unsigned)
  <1><2c>: Abbrev Number: 3 (DW_TAG_variable)
     <2d>   DW_AT_name        : i
     <2f>   DW_AT_type        : <0x23>
     <33>   DW_AT_location    : 0x0      (location list)

Contents of the .debug_loc section:

     Offset   Begin    End      Expression
     00000000 080483d5 080483e6 (DW_OP_reg2 (edx); DW_OP_piece: 4; 
DW_OP_reg3 (ebx); DW_OP_piece: 4)
     00000000 <End of list>

However, the symbol 'i' can't be found unless I type 'tab' after command 
'p'.
(gdb) p i
No symbol "i" in current context.
(gdb) p // type 'tab'
Display all 7422 possibilities? (y or n) // type 'n'
(gdb) p/x i
$2 = 0x45396ff4bfffeff4

Turning 'debug symtab-create' on tells me that 'tab' triggers creating 
symtab, and I think that is the reason 'i' can be found after typing 
'tab'.  What should I complete/add in my faked dwarf information so that 
symbol 'i' can be found directly when the executable is loaded?  without 
typing 'tab' to resolve symbol 'i'.

-- 
Yao

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

* Re: Symbol can't be found unless type 'tab'
  2012-09-10 12:52 Symbol can't be found unless type 'tab' Yao Qi
@ 2012-09-10 13:18 ` Jan Kratochvil
  2012-09-12  7:45   ` Yao Qi
  0 siblings, 1 reply; 8+ messages in thread
From: Jan Kratochvil @ 2012-09-10 13:18 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb

On Mon, 10 Sep 2012 14:51:29 +0200, Yao Qi wrote:
>  <1><2c>: Abbrev Number: 3 (DW_TAG_variable)
>     <2d>   DW_AT_name        : i
>     <2f>   DW_AT_type        : <0x23>
>     <33>   DW_AT_location    : 0x0      (location list)

I guess because GDB does not like such complicated location expression for
glboal variables.

read_partial_die (const struct die_reader_specs *reader,
        case DW_AT_location:
          else if (attr_form_is_section_offset (&attr))
              dwarf2_complex_location_expr_complaint ();
+
add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
    case DW_TAG_variable:
      if (pdi->d.locdesc)
        addr = decode_locdesc (pdi->d.locdesc, cu);


There was a nice cleanup of it in:
	[patch 2/2] Fix decode_locdesc for gcc-4.7.x optimized DWARF
	http://sourceware.org/ml/gdb-patches/2011-07/msg00762.html
but I had to later revert it
	[commit] [patch#2] fetch result of locdesc expressions as integer (not address)
	http://sourceware.org/ml/gdb-patches/2011-10/msg00462.html
due to all the hacks on hacks in GDB needing to be cleaned up first.


Regards,
jan

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

* Re: Symbol can't be found unless type 'tab'
  2012-09-10 13:18 ` Jan Kratochvil
@ 2012-09-12  7:45   ` Yao Qi
  2012-09-12  8:07     ` Jan Kratochvil
  0 siblings, 1 reply; 8+ messages in thread
From: Yao Qi @ 2012-09-12  7:45 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb

On 09/10/2012 09:18 PM, Jan Kratochvil wrote:
> On Mon, 10 Sep 2012 14:51:29 +0200, Yao Qi wrote:
>> >  <1><2c>: Abbrev Number: 3 (DW_TAG_variable)
>> >     <2d>   DW_AT_name        : i
>> >     <2f>   DW_AT_type        : <0x23>
>> >     <33>   DW_AT_location    : 0x0      (location list)
> I guess because GDB does not like such complicated location expression for
> glboal variables.

Jan, thanks for the pointer.

The "symptom" is symbol is not found in psymtab, but in symtab when I 
press 'tab' which triggers converting psymtab to symtab.  I wonder why 
symbol 'i' is *not* included in psymtab.  Examine the source of 
dwarf2read.c:add_partial_symbol, especially the case block for 
'DW_TAG_variable', gives me some clue, and I add attribute 
DW_AT_external to symbol 'i' like this,

  <1><33>: Abbrev Number: 3 (DW_TAG_variable)
     <34>   DW_AT_name        : i
     <36>   DW_AT_type        : <0x2a>
     <3a>   DW_AT_external    : 1  <--- here
     <3b>   DW_AT_location    : 0x0      (location list)

and then symbol 'i' can be found by GDB without typing extra 'tab'.
-- 
Yao

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

* Re: Symbol can't be found unless type 'tab'
  2012-09-12  7:45   ` Yao Qi
@ 2012-09-12  8:07     ` Jan Kratochvil
  2012-09-12 11:34       ` Yao Qi
  0 siblings, 1 reply; 8+ messages in thread
From: Jan Kratochvil @ 2012-09-12  8:07 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb

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

On Wed, 12 Sep 2012 09:44:44 +0200, Yao Qi wrote:
> On 09/10/2012 09:18 PM, Jan Kratochvil wrote:
> >On Mon, 10 Sep 2012 14:51:29 +0200, Yao Qi wrote:
> >>>  <1><2c>: Abbrev Number: 3 (DW_TAG_variable)
> >>>     <2d>   DW_AT_name        : i
> >>>     <2f>   DW_AT_type        : <0x23>
> >>>     <33>   DW_AT_location    : 0x0      (location list)
> >I guess because GDB does not like such complicated location expression for
> >glboal variables.
> 
> Jan, thanks for the pointer.
> 
> The "symptom" is symbol is not found in psymtab, but in symtab when
> I press 'tab' which triggers converting psymtab to symtab.  I wonder
> why symbol 'i' is *not* included in psymtab.

Because it has the complex location I suggested above.


> Examine the source of
> dwarf2read.c:add_partial_symbol, especially the case block for
> 'DW_TAG_variable', gives me some clue, and I add attribute
> DW_AT_external to symbol 'i' like this,
> 
>  <1><33>: Abbrev Number: 3 (DW_TAG_variable)
>     <34>   DW_AT_name        : i
>     <36>   DW_AT_type        : <0x2a>
>     <3a>   DW_AT_external    : 1  <--- here
>     <3b>   DW_AT_location    : 0x0      (location list)
> 
> and then symbol 'i' can be found by GDB without typing extra 'tab'.

It is difficult to talk about the problem when you have not provided the
testcase, I have provided mine now.

But DW_AT_external is not significant to GDB as GDB can display even static
variables, even when they are not in current CU.

It is good to verify 'maintenance info symtabs' is empty during these
experiments, when one tries to print the variable.

I am very sure that this complex DW_AT_location is not properly supported by
psymtabs in GDB, this is one of the reasons I was doing the fix and its later
undo as I referenced in the previous mail.

Why didn't use just normal DWARF block, instead of the location list?
This part does not matter for your testcase and it will work with GDB.


Jan

[-- Attachment #2: i.c --]
[-- Type: text/plain, Size: 7 bytes --]

int i;

[-- Attachment #3: i.s --]
[-- Type: text/plain, Size: 2693 bytes --]

	.file	"i.c"
	.text
.Ltext0:
	.comm	i,4,4
.Letext0:
	.file 1 "i.c"
	.section	.debug_info,"",@progbits
.Ldebug_info0:
	.long	1f - 2f	# Length of Compilation Unit Info
2:
	.value	0x4	# DWARF version number
	.long	.Ldebug_abbrev0	# Offset Into Abbrev. Section
	.byte	0x8	# Pointer Size (in bytes)
	.uleb128 0x1	# (DIE (0xb) DW_TAG_compile_unit)
	.long	.LASF0	# DW_AT_producer: "GNU C 4.6.3 20120306 (Red Hat 4.6.3-2) -mtune=generic -march=x86-64 -g"
	.byte	0x2	# DW_AT_language
	.ascii "i.c\0"	# DW_AT_name
#	.long	.LASF1	# DW_AT_comp_dir: "/home/jkratoch/t"
#	.long	.Ldebug_line0	# DW_AT_stmt_list
	.uleb128 0x2	# (DIE (0x1d) DW_TAG_variable)
	.ascii "i\0"	# DW_AT_name
#	.byte	0x1	# DW_AT_decl_file (i.c)
#	.byte	0x1	# DW_AT_decl_line
	.long	die30-.Ldebug_info0	# DW_AT_type
			# DW_AT_external
	.uleb128 0x9	# DW_AT_location
	.byte	0x3	# DW_OP_addr
	.quad	i
die30:
	.uleb128 0x3	# (DIE (0x30) DW_TAG_base_type)
	.byte	0x8	# DW_AT_byte_size
	.byte	0x5	# DW_AT_encoding
	.ascii "int\0"	# DW_AT_name
	.byte	0	# end of children of DIE 0xb
1:
	.section	.debug_abbrev,"",@progbits
.Ldebug_abbrev0:
	.uleb128 0x1	# (abbrev code)
	.uleb128 0x11	# (TAG: DW_TAG_compile_unit)
	.byte	0x1	# DW_children_yes
	.uleb128 0x25	# (DW_AT_producer)
	.uleb128 0xe	# (DW_FORM_strp)
	.uleb128 0x13	# (DW_AT_language)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3	# (DW_AT_name)
	.uleb128 0x8	# (DW_FORM_string)
#	.uleb128 0x1b	# (DW_AT_comp_dir)
#	.uleb128 0xe	# (DW_FORM_strp)
#	.uleb128 0x10	# (DW_AT_stmt_list)
#	.uleb128 0x17	# (DW_FORM_sec_offset)
	.byte	0
	.byte	0
	.uleb128 0x2	# (abbrev code)
	.uleb128 0x34	# (TAG: DW_TAG_variable)
	.byte	0	# DW_children_no
	.uleb128 0x3	# (DW_AT_name)
	.uleb128 0x8	# (DW_FORM_string)
#	.uleb128 0x3a	# (DW_AT_decl_file)
#	.uleb128 0xb	# (DW_FORM_data1)
#	.uleb128 0x3b	# (DW_AT_decl_line)
#	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x49	# (DW_AT_type)
	.uleb128 0x13	# (DW_FORM_ref4)
#	.uleb128 0x3f	# (DW_AT_external)
#	.uleb128 0x19	# (DW_FORM_flag_present)
	.uleb128 0x2	# (DW_AT_location)
	.uleb128 0x18	# (DW_FORM_exprloc)
	.byte	0
	.byte	0
	.uleb128 0x3	# (abbrev code)
	.uleb128 0x24	# (TAG: DW_TAG_base_type)
	.byte	0	# DW_children_no
	.uleb128 0xb	# (DW_AT_byte_size)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3e	# (DW_AT_encoding)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3	# (DW_AT_name)
	.uleb128 0x8	# (DW_FORM_string)
	.byte	0
	.byte	0
	.byte	0
	.section	.debug_line,"",@progbits
.Ldebug_line0:
	.section	.debug_str,"MS",@progbits,1
.LASF0:
	.string	"GNU C 4.6.3 20120306 (Red Hat 4.6.3-2) -mtune=generic -march=x86-64 -g"
.LASF1:
	.string	"/home/jkratoch/t"
	.ident	"GCC: (GNU) 4.6.3 20120306 (Red Hat 4.6.3-2)"
	.section	.note.GNU-stack,"",@progbits

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

* Re: Symbol can't be found unless type 'tab'
  2012-09-12  8:07     ` Jan Kratochvil
@ 2012-09-12 11:34       ` Yao Qi
  2012-09-12 12:33         ` Jan Kratochvil
  0 siblings, 1 reply; 8+ messages in thread
From: Yao Qi @ 2012-09-12 11:34 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb

On 09/12/2012 04:06 PM, Jan Kratochvil wrote:
> Why didn't use just normal DWARF block, instead of the location list?
> This part does not matter for your testcase and it will work with GDB.

No special reason really.  Are you suggesting create dwarf like this?

  <1><33>: Abbrev Number: 3 (DW_TAG_variable)
     <34>   DW_AT_name        : i
     <36>   DW_AT_type        : <0x2a>
     <3a>   DW_AT_external    : 1
     <3b>   DW_AT_location    : 6 byte block: 52 93 4 53 93 4 
(DW_OP_reg2 (edx); DW_OP_piece: 4; DW_OP_reg3 (ebx); DW_OP_piece: 4)

-- 
Yao

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

* Re: Symbol can't be found unless type 'tab'
  2012-09-12 11:34       ` Yao Qi
@ 2012-09-12 12:33         ` Jan Kratochvil
  2012-09-12 13:37           ` Yao Qi
  0 siblings, 1 reply; 8+ messages in thread
From: Jan Kratochvil @ 2012-09-12 12:33 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb

On Wed, 12 Sep 2012 13:33:34 +0200, Yao Qi wrote:
> On 09/12/2012 04:06 PM, Jan Kratochvil wrote:
> >Why didn't use just normal DWARF block, instead of the location list?
> >This part does not matter for your testcase and it will work with GDB.
> 
> No special reason really.  Are you suggesting create dwarf like this?
> 
>  <1><33>: Abbrev Number: 3 (DW_TAG_variable)
>     <34>   DW_AT_name        : i
>     <36>   DW_AT_type        : <0x2a>
>     <3a>   DW_AT_external    : 1
>     <3b>   DW_AT_location    : 6 byte block: 52 93 4 53 93 4
> (DW_OP_reg2 (edx); DW_OP_piece: 4; DW_OP_reg3 (ebx); DW_OP_piece: 4)

Oops, you are right, this also cannot work.

You have to put it into a function as a local variable.


Sorry,
Jan

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

* Re: Symbol can't be found unless type 'tab'
  2012-09-12 12:33         ` Jan Kratochvil
@ 2012-09-12 13:37           ` Yao Qi
  2012-09-12 13:45             ` Jan Kratochvil
  0 siblings, 1 reply; 8+ messages in thread
From: Yao Qi @ 2012-09-12 13:37 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb

On 09/12/2012 08:32 PM, Jan Kratochvil wrote:
> On Wed, 12 Sep 2012 13:33:34 +0200, Yao Qi wrote:
>> On 09/12/2012 04:06 PM, Jan Kratochvil wrote:
>>> Why didn't use just normal DWARF block, instead of the location list?
>>> This part does not matter for your testcase and it will work with GDB.
>>
>> No special reason really.  Are you suggesting create dwarf like this?
>>
>>   <1><33>: Abbrev Number: 3 (DW_TAG_variable)
>>      <34>   DW_AT_name        : i
>>      <36>   DW_AT_type        : <0x2a>
>>      <3a>   DW_AT_external    : 1
>>      <3b>   DW_AT_location    : 6 byte block: 52 93 4 53 93 4
>> (DW_OP_reg2 (edx); DW_OP_piece: 4; DW_OP_reg3 (ebx); DW_OP_piece: 4)
>
> Oops, you are right, this also cannot work.
>

I am not sure what do you mean by "this also cannot work", but it works 
for me, at least for my test purpose.

(gdb) b middle_middle
Breakpoint 1 at 0x80483ca
(gdb) run
Starting program: 
/home/yao/Source/gnu/gdb/build-git/x86/gdb/testsuite/gdb.mi/mi-reg-changed

Breakpoint 1, 0x080483ca in middle_middle ()
(gdb) p/x i
$2 = 0x45396ff4bfffefe4
(gdb) p/x $ebx
$3 = 0x45396ff4
(gdb) p/x $edx
$4 = 0xbfffefe4

-- 
Yao

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

* Re: Symbol can't be found unless type 'tab'
  2012-09-12 13:37           ` Yao Qi
@ 2012-09-12 13:45             ` Jan Kratochvil
  0 siblings, 0 replies; 8+ messages in thread
From: Jan Kratochvil @ 2012-09-12 13:45 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb

On Wed, 12 Sep 2012 15:36:44 +0200, Yao Qi wrote:
> I am not sure what do you mean by "this also cannot work", but it
> works for me, at least for my test purpose.

This is because 'b middle_middle' has expanded psymtab->symtab.

If you do 'p/x i' as the very first GDB command it will not work.

You could also keep there the location list in such case, it would work the
same.

See what you will see with 'set complaints 100', 'file ./gdb.mi/mi-reg-changed'.

I believe it would make the testcase magic if you move the 'i' variable DIE
into some function.  But if you put some warning into the testcase source it
is IMO also acceptable the way you have it.


Thanks,
Jan

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

end of thread, other threads:[~2012-09-12 13:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-10 12:52 Symbol can't be found unless type 'tab' Yao Qi
2012-09-10 13:18 ` Jan Kratochvil
2012-09-12  7:45   ` Yao Qi
2012-09-12  8:07     ` Jan Kratochvil
2012-09-12 11:34       ` Yao Qi
2012-09-12 12:33         ` Jan Kratochvil
2012-09-12 13:37           ` Yao Qi
2012-09-12 13:45             ` Jan Kratochvil

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).