Skip to content
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

runtime: FuncForPc on reflect.Pointer() result does not work properly #57383

Closed
z1293271436 opened this issue Dec 17, 2022 · 3 comments
Closed
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@z1293271436
Copy link

What version of Go are you using (go version)?

$ go version  1.19.4

Does this issue reproduce with the latest release?

no

What operating system and processor architecture are you using (go env)?

go env Output
$ go env  this bug not cast by system

What did you do?

func (ctrl *BaseController) setFunc(f func(), father *BaseController) {
ctrl.rpcFunc = f
ctrl.http = &httpBase{Data: map[string]any{}}
ptr := reflect.ValueOf(f).Pointer()
functionInfo := runtime.FuncForPC(ptr)
file, line := functionInfo.FileLine(ptr)
file = file[strings.LastIndex(file, "/")+1:] //strings.ReplaceAll(file, utils.GetRuntimePath()+"/", "")
name := functionInfo.Name()
file = name[:strings.LastIndex(name, ".")]
file = file[:strings.LastIndex(file, ".")]
name = name[strings.LastIndex(name, ".")+1:]
ctrl.funcName = utils.CombineString(name[strings.LastIndex(name, ".")+1:], "(", file, ":", utils.AllToString(line), ")")
ctrl.father = father
}

What did you expect to see?

if use 1.17 this file and line return the value I want but now it work not well
it not return the function in witch file and line number

What did you see instead?

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 17, 2022
@seankhliao
Copy link
Member

This is insufficient info to reproduce or diagnose the issue.

@randall77
Copy link
Contributor

A self-contained reproducer would be nice, thanks.

That said, I think this has to do with wrappers, similar (maybe dup?) of #51774 or #52809.

I would be interested in knowing if the CL for #51774 (CL 416455) helps in your situation.

More generally, runtime.FuncForPC(reflect.Pointer(..some func..)) is not guaranteed to be stable. The docs for reflect.Pointer() only guarantee nil vs. non-nil result.

@randall77 randall77 changed the title affected/package: runtimeforPc is not work properly runtime: runtimeforPc on reflect.Pointer() result does not work properly Dec 20, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 20, 2022
@randall77 randall77 changed the title runtime: runtimeforPc on reflect.Pointer() result does not work properly runtime: FuncForPc on reflect.Pointer() result does not work properly Dec 20, 2022
@z1293271436
Copy link
Author

A self-contained reproducer would be nice, thanks.

That said, I think this has to do with wrappers, similar (maybe dup?) of #51774 or #52809.

I would be interested in knowing if the CL for #51774 (CL 416455) helps in your situation.

More generally, runtime.FuncForPC(reflect.Pointer(..some func..)) is not guaranteed to be stable. The docs for reflect.Pointer() only guarantee nil vs. non-nil result.

I cc,my question is same as other person has been set ,I'll close my issue

@golang golang locked and limited conversation to collaborators Dec 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants