Just for information, I've written an issue on go compiler to follow this 
evolution: https://github.com/golang/go/issues/67744 

Le vendredi 31 mai 2024 à 10:15:02 UTC+2, Benoît Marguerie a écrit :

> Good question !
>
> But delve mainly extracts its symbols from Dwarf info. And when I try to 
> get them with your code, I obtain this:
>
> *~/tmp$ objdump -W main | grep -i constV    <2547>   DW_AT_name        : 
> main.constValueInt*
>
> We can see that the compiler puts some debug tags for const int values but 
> not for the others.
>
> From here, I've searched into Go SDK for dwarf information and I found in 
> the compiler sources this (file src/cmd/compile/internal/gc/obj.go:163-189 
> func dumpGlobalConst):
> // only export integer constants for now
> if !t.IsInteger() {
> return
> }
>
> *So, for the moment, it seems to be a deliberate limitation of Go 
> compiler.*
>
> Many thanks for your help @Jan and @Kurtis !
> Benoît
>
> NB: just for information, I'm working with Go 1.22.3, dlv 1.22.1 , objdump 
> 2.38)
>
> Le vendredi 31 mai 2024 à 07:30:52 UTC+2, Kurtis Rader a écrit :
>
>> Your question should have included more information such as the Go 
>> version. Nonetheless, I don't see how Delve is able to resolve "myValueInt" 
>> in your example. I modified your code to include non-const versions of the 
>> symbols:
>>
>> package main
>>
>>
>> import "fmt"
>>
>>
>> const constValueStr = "abc"
>> const constValueInt = 12
>> const constValueFloat = 1.2
>>
>>
>> var varValueStr = "def"
>> var varValueInt = 13
>>
>>
>> func main() {
>>         fmt.Println(constValueStr, constValueInt, constValueFloat, 
>> varValueStr, varValueInt)
>> }
>>
>>
>> I put that code in a file named "x.go" and compiled it with "go build 
>> x.go". The "strings" command shows both "varValue" symbols but neither 
>> "constValue" symbols:
>>
>> elvish> strings - x | grep varValue
>> _main.varValueInt
>> _main.varValueStr
>> elvish> strings - x | grep constValue
>> Exception: grep exited with 1
>>   [tty 156]:1:15-29: strings - x | grep constValue
>>
>>
>> Delve is able to resolve three of the five symbols:
>>
>> elvish> dlv exec x
>> Type 'help' for list of commands.
>> (dlv) print main.varValueInt
>> 13
>> (dlv) print main.constValueInt
>> 12
>> (dlv) print main.constValueFloat
>> Command failed: could not find symbol value for main
>> (dlv) print main.varValueStr
>> (unreadable could not read string at 0x100086f47 due to protocol error 
>> E08 during memory read for packet $m100086f47,3)
>> (dlv) print main.constValueStr
>> Command failed: could not find symbol value for main
>>
>>
>> It is not obvious how Delve is able to resolve "main.constValueInt" since 
>> that string does not appear in the binary according to the "strings - x" 
>> command. So I think the more interesting question is how Delve is able to 
>> resolve the "main.constValueInt" symbol but not the two other const symbols.
>>
>>
>> On Thu, May 30, 2024 at 1:58 AM Benoît Marguerie <bmar...@gmail.com> 
>> wrote:
>>
>>> or, in a easier way, a full "copy/paste" example of code:
>>>
>>> package main
>>>
>>> import "fmt"
>>>
>>> const myValueStr = "try"
>>> const myValueInt = 12
>>>
>>> func main() {
>>> fmt.Println("Instruction only to put a breakpoint")
>>> }
>>>
>>>
>>> Le jeudi 30 mai 2024 à 10:53:50 UTC+2, Benoît Marguerie a écrit :
>>>
>>>> Of course!
>>>> The code can be really simple like this:
>>>>
>>>>
>>>> *const myValueStr = "try"const myValueInt = 12*
>>>>
>>>>
>>>>
>>>> *func DoSomething() {   fmt.Println("Instruction only to put a 
>>>> breakpoint")}*
>>>>
>>>>
>>>> and the result with delve:
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> *(dlv) print %v myValueInt12(dlv) print %v myValueStrCommand failed: 
>>>> could not find symbol value for myValueStr*
>>>>
>>>> Benoit
>>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to golang-nuts...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/c938f107-9bca-4b8e-a10c-f8deef396c87n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/golang-nuts/c938f107-9bca-4b8e-a10c-f8deef396c87n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>> -- 
>> Kurtis Rader
>> Caretaker of the exceptional canines Junior and Hank
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e240b3c6-84f1-4160-90e6-8a3698e83dc4n%40googlegroups.com.

Reply via email to