-
Notifications
You must be signed in to change notification settings - Fork 18k
debug/dwarf: r.Next() returns wrong ent when DWARF5 used. #57046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you make the test file available somewhere? Or provide a standalone test? Thanks. CC @thanm @aclements |
vmlinux is too big to share.
|
Test program
|
Attach the init/main.o instead https://github.com/joeyjiaojg/go/raw/master/test/dwarf/dwarf5.o |
It's going to be difficult for us to fix this problem if we can't recreate it ourselves. Anything you can do to make that possible would be appreciated. Thanks. |
you can reproduce
|
To avoid confusion, you can use the test steps below only:
|
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
Reopening because @joeyjiaojg provided repro instructions. |
any progress on this? |
TEST_FILE #include <stdio.h>
// Define a structure named "example"
struct example {
int id;
char name[50];
float value;
};
// Define a function also named "example"
void example(struct example* item) {
printf("ID: %d\n", item->id);
printf("Name: %s\n", item->name);
printf("Value: %.2f\n", item->value);
}
int main() {
// Create and initialize an instance of the structure
struct example my_example = {
.id = 42,
.name = "Test Item",
.value = 3.14159
};
// Call the function with the same name
example(&my_example);
return 0;
} BUILD_CMD clang -g -gdwarf-5 -glldb -O0 -Xclang -debug-info-kind=constructor example.c -o example DWARFDUMP ❱ xcrun dwarfdump example.dSYM --name example
example.dSYM/Contents/Resources/DWARF/example: file format Mach-O arm64
0x0000002d: DW_TAG_subprogram
DW_AT_low_pc (0x00000001000004b0)
DW_AT_high_pc (0x0000000100000524)
DW_AT_frame_base (DW_OP_reg29 W29)
DW_AT_name ("example")
DW_AT_decl_file ("/private/tmp/dwarf5_test/example.c")
DW_AT_decl_line (11)
DW_AT_prototyped (true)
DW_AT_external (true)
0x00000068: DW_TAG_structure_type
DW_AT_name ("example")
DW_AT_byte_size (0x3c)
DW_AT_decl_file ("/private/tmp/dwarf5_test/example.c")
DW_AT_decl_line (4) TEST_RUNNER package main
import (
"debug/dwarf"
"debug/macho"
"fmt"
)
func main() {
file, err := macho.Open("example.dSYM/Contents/Resources/DWARF/example")
if err != nil {
panic(err)
}
debugInfo, err := file.DWARF()
if err != nil {
panic(err)
}
ent, err := getEntryByOffset(debugInfo, 0x0000002d)
if err != nil {
panic(err)
}
fmt.Printf("%v\n", ent)
ent, _ = getEntryByOffset(debugInfo, 0x00000068)
fmt.Printf("%v\n", ent)
}
func getEntryByOffset(debugInfo *dwarf.Data, offset dwarf.Offset) (*dwarf.Entry, error) {
r := debugInfo.Reader()
r.Seek(offset)
return r.Next()
} TEST_RESULTS go run main.go
&{45 Subprogram true [{Lowpc 2251821288521748 ClassAddress} {Highpc 116 ClassConstant} {FrameBase [109] ClassExprLoc} {Name "char" ClassString} {DeclFile 0 ClassConstant} {DeclLine 11 ClassConstant} {Prototyped true ClassFlag} {External true ClassFlag}]}
&{104 StructType true [{Name "char" ClassString} {ByteSize 60 ClassConstant} {DeclFile 0 ClassConstant} {DeclLine 4 ClassConstant}]} |
strangely enough when just iterating over the DIEs via r.Next() I can hit the |
😭 |
This is being looked at, you can follow along in this tentative CL: https://go-review.googlesource.com/c/go/+/628876 if you want more info. |
nice! I maintain a fork and I solved it for my own purposes in a very similar way, but your's is cleaner ;) There's also the NEW debug_names that tells you the exact CU index for the entry which might be useful to you, but I don't think looking up types/entries by names is something that pkg needs to do. |
Change https://go.dev/cl/655976 mentions this issue: |
What version of Go are you using (
go version
)?go 1.19.3
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?What did you do?
Above is extracted from vmlinux (compiled by clang-15) by llvm-dwarfdump-15, when linux kernel compiled with DWARF5 debug info, go debug/dwarf can't decode entry at 0x000160e6 correctly.
Test program
What did you expect to see?
The 2nd printf should print ent name as rcu_read_unlock.
What did you see instead?
The 2nd printf should print ent name of some other subprogram.
The text was updated successfully, but these errors were encountered: