microsoft / microsoft/vscode-cpptools
Start gdb fail when attach debug a program.(Authentication is needed to run `/usr/bin/gdb' as the super user)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Description
Type: Debugger
Describe the bug
- OS and Version: Ubuntu 18.04
- VS Code Version: 1.42
- C/C++ Extension Version: 0.26.3
- Other extensions you installed (and if the issue persists after disabling them): Python
- A clear and concise description of what the bug is:
I want to mix debug C++ and python code. So I launch my python program with ptvsd. Then I start my python debug configuration and c++ debug configuration . When I launch my gdb debug configuration, there are following failure from debug terminal:
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/bin/gdb' as the super user
Authenticating as: hanbing
Password: [1] + Stopped (tty output) /usr/bin/pkexec "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-zmh829r2.jk4" 1>"/tmp/Microsoft-MIEngine-Out-jh3h8jnd.mmk"
You have stopped jobs.
It's because gdb can't get the root permission when start attach to other program. It's is a known issue in https://code.visualstudio.com/docs/cpp/cpp-debug
Linux:
GDB needs elevated permissions to attach to a process. When using attach to process, you need to provide your password before the debugging session can begin.
But there is no prompt to let me input the password. It raise error directly.
To Reproduce
my c++ extention fputsmodule.cc
#define PY_SSIZE_T_CLEAN
#include <Python.h>
static PyObject *StringTooShortError = NULL;
static PyObject *method_fputs(PyObject *self, PyObject *args, PyObject *kw) {
char *str, *filename = NULL;
int bytes_copied = -1;
/* Parse arguments */
char *kwlist[] = {"content", "filename", NULL};
if(!PyArg_ParseTupleAndKeywords(args, kw, "ss", kwlist, &str, &filename)) {
return NULL;
}
if (strlen(str) < 10) {
/* Passing custom exception */
PyErr_SetString(StringTooShortError, "String length must be greater than 10");
return NULL;
}
FILE *fp = fopen(filename, "w");
bytes_copied = fputs(str, fp);
fclose(fp);
return (PyObject *)Py_BuildValue("i", bytes_copied);
}
static PyMethodDef FputsMethods[] = {
{"fputs", (PyCFunction)method_fputs, METH_VARARGS | METH_KEYWORDS, "Python interface for fputs C library function"},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef fputsmodule = {
PyModuleDef_HEAD_INIT,
"fputs",
"Python interface for the fputs C library function",
-1,
FputsMethods
};
PyMODINIT_FUNC PyInit_fputs(void) {
/* Assign module value */
PyObject *module = PyModule_Create(&fputsmodule);
/* Initialize new exception object */
StringTooShortError = PyErr_NewException("fputs.StringTooShortError", NULL, NULL);
/* Add exception object to your module */
PyModule_AddObject(module, "StringTooShortError", StringTooShortError);
return module;
}
setup.py
from distutils.core import setup, Extension
def main():
setup(name="fputs",
version="1.0.0",
description="Python interface for the fputs C library function",
author="hanbing",
author_email="beatmight@gmail.com",
ext_modules=[Extension("fputs", ["fputsmodule.cc"], language="c++")])
if __name__ == "__main__":
main()
fputs_test.py
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--ptvsd", action="store_true", help="是否启动ptvsd调试。")
args = parser.parse_args()
if args.ptvsd:
import ptvsd
ptvsd.enable_attach(address =('127.0.0.1', 10010), redirect_output=True)
ptvsd.wait_for_attach()
import fputs
fputs.fputs("hello world! You are good!", "hello.txt")
print("hello world!")
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python Attach (local) proc 0",
"type": "python",
"request": "attach",
"pathMappings": [
{
"localRoot": "${workspaceFolder}", // You may also manually specify the directory containing your source code.
"remoteRoot": "${workspaceFolder}", // Linux example; adjust as necessary for your OS and situation.
}
],
"port": 10010,
"host": "localhost"
},
{
"name": "GDB Attach proc 0",
"type": "cppdbg",
"request": "attach",
"program": "/home/hanbing/anaconda3/bin/python",
"processId": "${command:pickProcess}",
"MIMode": "gdb"
}
]
}
First compile the c++ extention
python setup.py build_ext --inplace
Then start the ptvsd server
python fputs_test.py --ptvsd
Then start "Python Attach (local) proc 0"
Then, start "GDB Attach proc 0", the error raised.
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/bin/gdb' as the super user
Authenticating as: hanbing
Password: [1] + Stopped (tty output) /usr/bin/pkexec "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-zmh829r2.jk4" 1>"/tmp/Microsoft-MIEngine-Out-jh3h8jnd.mmk"
You have stopped jobs.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the attach flow using fputsmodule.cc, setup.py, fputs_test.py, and launch.json on Ubuntu 18.04, starting with the GDB attach configuration and its debug terminal output. Investigate why pkexec authentication has no usable password prompt; done means the C++ debugger can attach to the Python process after authentication.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- developer-experience, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100