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

stepin function error in WSL #6081

Closed
fengxiaohu opened this issue Sep 4, 2020 · 1 comment
Closed

stepin function error in WSL #6081

fengxiaohu opened this issue Sep 4, 2020 · 1 comment

Comments

@fengxiaohu
Copy link

Type: Debugger

Describe the bug

  • OS and Version: WSL:Ubuntu-18.04 Windows10
  • VS Code Version: 1.48.0 (user setup)
  • C/C++ Extension Version: Version 0.30.0-insiders4: September 1, 2020
  • Other extensions you installed (and if the issue persists after disabling them):
  • A clear and concise description of what the bug is:
    I want to step into the function pthread_create.c of external library pthread.
    ERROR:
    Unable to open 'pthread_create.c': Unable to read file 'vscode-remote://wsl+ubuntu-18.04/build/glibc-OTsEL5/glibc-2.27/nptl/pthread_create.c' (Error: Unable to resolve non-existing file 'vscode-remote://wsl+ubuntu-18.04/build/glibc-OTsEL5/glibc-2.27/nptl/pthread_create.c').

To Reproduce
Please include a code sample and launch.json configuration.
Steps to reproduce the behavior:

  1. create test file petersonAlgorithm.c
    2.Build
  2. set breakpoints at pthread_create(&p1,NULL,func,(void*)0
  3. Debug See error :
    Unable to open 'pthread_create.c': Unable to read file 'vscode-remote://wsl+ubuntu-18.04/build/glibc-OTsEL5/glibc-2.27/nptl/pthread_create.c' (Error: Unable to resolve non-existing file 'vscode-remote://wsl+ubuntu-18.04/build/glibc-OTsEL5/glibc-2.27/nptl/pthread_create.c').

Additional context
test file petersonAlgorithm.c Code:

#include <stdio.h> 
#include <pthread.h> 

  
int flag[2];
int turn;
const int MAX = 1e9;
int ans = 0;

void lock_init()
{
    flag[0] = flag[1]=0;
    turn = 0;
}
void lock(int self)
{
    flag[self] = 1;//lock
    turn = 1-self;// first give the other thread the chance to 
    // acquire lock 
    while(flag[1-self]==1 && turn == 1-self);// exit until 
    
}
void unlock(int self)
{
    flag[self] =0;
}
void* func(void *s)
{
    int i=0;
    int self = (int*)s;
    printf("thread Entered:%d\n",self);
    lock(self);
    
    for(i=0;i<MAX;i++)
    {
        ans++;
        unlock(self);
    }
}
int main()
{
    pthread_t p1,p2;
    lock_init();
    pthread_create(&p1,NULL,func,(void*)0); 
    pthread_create(&p2,NULL,func,(void*)1);
    pthread_join(p1,NULL);
    pthread_join(p2,NULL);
    printf("Actual Count: %d | Expected Count: %d\n", 
                                        ans, MAX*2); 
    return 0;
}

launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        {
            "name": "(gdb) petersonAlgorithm ",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/petersonAlgorithm ",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }

    ]
}

task.json

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "shell",
			"label": "C/C++: gcc build active file",
			"command": "/usr/bin/gcc",
			"args": [
				"-g",
				"${file}",
				"-pthread",
				"-o",
				"${fileDirname}/${fileBasenameNoExtension}"
			],
			"options": {
				"cwd": "${workspaceFolder}"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			}
		}
	]
}

console output

thread Entered:0
thread Entered:1
Actual Count: 1156311223 | Expected Count: 2000000000
@WardenGnaw
Copy link
Member

Not an error. Message is trying to open pthread_create.c which is a library file. Unless you have the source file it will not step into that method.

Duplicate of: #811

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants