microsoft / microsoft/vscode-cpptools
Start gdb fail when attach debug a program.(Authentication is needed to run `/usr/bin/gdb' as the super user)
Nessuno ha ancora preso questa issue.
- Lingua principale
- TypeScript
- Stelle
- 6.2k
- Fork
- 1.7k
- Merge medio
- 14h 46m
- PR unite (30g)
- 61
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riprodurre il flusso di attach usando fputsmodule.cc, setup.py, fputs_test.py e launch.json su Ubuntu 18.04, iniziando dalla configurazione di attach di GDB e dall’output del terminale di debug. Indagare sul motivo per cui l’autenticazione pkexec non dispone di una richiesta di password utilizzabile; il lavoro è completato quando il debugger C++ può eseguire l’attach al processo Python dopo l’autenticazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- cpp, python
- Ambito
- developer-experience, devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100