如何在gdb中获取当前调试过程的pid?

时间:2016-04-18 21:05:01

标签: c++ linux gdb

在gdb里面,什么命令会提供调试过程的pid?

大多数google results只讨论了在知道pid后如何将gdb附加到进程。

2 个答案:

答案 0 :(得分:17)

一种简单的方法是info inferior。这里我用自己调试gdb,这个命令显示调试对象的PID:

(top-gdb) info inferior
  Num  Description       Executable        
* 1    process 14068     /home/tromey/gdb/build/gdb/gdb 

你也可以调用普通的C函数:

(top-gdb) print getpid()
$3 = 14068

答案 1 :(得分:1)

另一种方法:

defaults._set('global', {

responsive: true,
responsiveAnimationDuration: 0,
maintainAspectRatio: true,
events: ['mousemove', 'mouseout', 'click', 'touchstart', 'touchmove'],
hover: {
    onHover: null,
    mode: 'nearest',
    intersect: true,
    animationDuration: 400
},
onClick: null,
defaultColor: 'rgba(0,0,0,0.1)',
defaultFontColor: '#0000ff',
defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
defaultFontSize: 12,
defaultFontStyle: 'normal',
showLines: true,

// Element defaults defined in element extensions
elements: {},

// Layout options such as padding
layout: {
    padding: {
        top: 0,
        right: 0,
        bottom: 0,
        left: 0
    }
}
});

module.exports = function() {

// Occupy the global variable of Chart, and create a simple base class
var Chart = function(item, config) {
    this.construct(item, config);
    return this;
};

Chart.Chart = Chart;

return Chart;
};`

查看有关gdb Python下级API的更多信息: https://sourceware.org/gdb/onlinedocs/gdb/Inferiors-In-Python.html#Inferiors-In-Python