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

cmd/cgo: wrong line info for C function calls when closing parenthesis is not on same line as last argument #49839

Closed
SHyx0rmZ opened this issue Nov 29, 2021 · 1 comment
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@SHyx0rmZ
Copy link
Contributor

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

$ go version
go version go1.17.3 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

go env Output
$ go env
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"

What did you do?

Below is as minimal of a program as I could get to reproduce the problem:

main.go:

package main

// #include "main.h"
import "C"
import (
	"unsafe"
)

type VkInstance C.VkInstance
type PhysicalDevice C.VkPhysicalDevice
type Result C.VkResult

func (Result) Error() string { return "" }

func vkEnumeratePhysicalDevices(instance VkInstance) ([]PhysicalDevice, error) {
	var count C.uint32_t
	result := C.vkEnumeratePhysicalDevices(
		(C.VkInstance)(unsafe.Pointer(instance)),
		&count,
		nil,
	)
	if result != C.VK_SUCCESS { // will be skipped by debugger
		return nil, Result(result)
	}
	devices := make([]PhysicalDevice, count)
	result = C.vkEnumeratePhysicalDevices(
		(C.VkInstance)(unsafe.Pointer(instance)),
		&count,
		(*C.VkPhysicalDevice)(unsafe.Pointer(&devices[0])))
	if result != C.VK_SUCCESS { // will *NOT* be skipped by debugger
		return nil, Result(result)
	}
	return devices, nil
}

func main() {
	_, _ = vkEnumeratePhysicalDevices(nil)
}

main.h:

#include <stdint.h>

typedef enum VkResult { VK_SUCCESS = 0, } VkResult;
typedef struct VkInstance_T *VkInstance;
typedef struct VkPhysicalDevice_T *VkPhysicalDevice;
VkResult vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices);

main.c:

#include "main.h"

VkResult vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices) {
    *pPhysicalDeviceCount = 1;
    return VK_SUCCESS;
}

What did you expect to see?

When single-stepping with a debugger, I expect to have the debugger highlight the line of code that will be executed next.

What did you see instead?

The debugger will trail behind the actually executed line.

SHyx0rmZ added a commit to SHyx0rmZ/go that referenced this issue Nov 29, 2021
When calling a C function, line information will be
incorrect if the function call's closing parenthesis
is not on the same line as the last argument. We add
a comment with the line info for the return statement
to guide debuggers to the correct line.

Fixes golang#49839.
@gopherbot
Copy link

Change https://golang.org/cl/367454 mentions this issue: cmd/cgo: add line info for return statements

@seankhliao seankhliao changed the title Wrong line info for C function calls when closing parenthesis is not on same line as last argument cmd/cgo: wrong line info for C function calls when closing parenthesis is not on same line as last argument Nov 29, 2021
@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 29, 2021
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Nov 29, 2021
@golang golang locked and limited conversation to collaborators May 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants