microsoft / microsoft/vscode-cpptools
Start gdb fail when attach debug a program.(Authentication is needed to run `/usr/bin/gdb' as the super user)
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 6.2k
- Forks
- 1.7k
- Ø Merge
- 14 Std. 46 Min.
- Gemergte PRs (30 T.)
- 61
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere den Attach-Ablauf mit fputsmodule.cc, setup.py, fputs_test.py und launch.json auf Ubuntu 18.04, beginnend mit der GDB-Attach-Konfiguration und der Ausgabe des Debug-Terminals. Untersuche, warum die pkexec-Authentifizierung keine verwendbare Passwortabfrage hat; abgeschlossen ist die Aufgabe, wenn der C++-Debugger sich nach der Authentifizierung an den Python-Prozess anhängen kann.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- cpp, python
- Bereich
- developer-experience, devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100