2017-05-15 2 views
0

Gdb에서 파이썬 API를 사용하여 새 매개 변수를 완전히 정의하는 방법을 알 수 없습니다. 나는 소스는 다음이 포함 된 스크립트를Gdb 파이썬 API로 새 매개 변수 생성

python 
param = gdb.Parameter("test", gdb.COMMAND_NONE, gdb.PARAM_OPTIONAL_FILENAME) 
param.set_doc = "This is the documentation" --> throws exception 
end 

내가 변경하고 사용하여 GDB의 값을 보여

(gdb) set test "hello world" 
This command is not documented. 
(gdb) show test 
This command is not documented. "hello world" 

gdb를 문서는 Parameter.set_doc을 언급,하지만 난 그것에 할당 할 때 내가 얻을 예외 :

AttributeError: 'gdb.Parameter' object has no attribute 'set_doc' 

이 설명서를 추가하려면 어떻게해야합니까? 또는이 "문서화되지 않음"메시지가 인쇄되지 않도록하려면 어떻게합니까?

답변

1

gdb.Parameter을 직접 인스턴스화하고 나중에 속성을 추가하여 새로운 매개 변수를 만들 수는 있지만 어쩌면 누군가가 대답 할 수 있습니다. 일반적으로 새로운 클래스 인 gdb.Parameter의 하위 클래스를 정의하여 필요한 속성을 정의합니다. 해당 클래스에 set_doc과 같은 클래스를 만들고 해당 클래스를 인스턴스화합니다.

$ cat test.py 
class TestParameter(gdb.Parameter): 
    """Manage the test parameter. 

    Usage: set test filename 
      show test 
    """ 
    set_doc = "This is the single-line documentation for set test" 
    show_doc = "This is the single-line documentation for show test" 
    def __init__(self): 
     super(TestParameter, self).__init__("test", gdb.COMMAND_NONE, 
              gdb.PARAM_OPTIONAL_FILENAME) 
     self.value="" 
    def get_set_string(self): 
     return "You have set test to " + self.value 
    def get_show_string(self, _): 
     return "The value of test is " + self.value 

TestParameter() 

$ gdb -q 
(gdb) source test.py 

을 보여줍니다 방법과 다양한 문서화 문자열이 표시됩니다 :

(gdb) set test .profile 
You have set test to .profile 
(gdb) show test 
The value of test is .profile 
+0

좋은 예 : 여기

(gdb) help set test This is the single-line documentation for set test Manage the test parameter. Usage: set test filename show test (gdb) help show test This is the single-line documentation for show test Manage the test parameter. Usage: set test filename show test (gdb) help set ... List of set subcommands: ... set test -- This is the single-line documentation for set test ... 

setshow에 의해 생성 된 출력의 다음은 수정 된 당신의 예는,이다 +1! 고마워. 'set' 명령을 사용하지 않을 수도 있습니까? gdb 함수에서'set' 명령을 사용하고 있습니다. 이제는 보지 않으려는 문서 문자열을 출력합니다. – gospes

+0

출력을 생성 할 때 사용자 정의 매개 변수의 'set'을 중지하는 방법을 찾지 못했습니다. 'get_set_string'을'' "'로하면, gdb는 빈 줄을 출력합니다. 'get_set_string'을 정의하지 않으면, gdb는'set_doc'의 값을 출력합니다. 'get_set_string'을 정의하지 않고'set_doc'을 정의하지 않으면, gdb는''이 명령은 문서화되어 있지 않습니다. " –