From 176cdc8069109107750d39b0093aad4130c2c63e Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Sun, 5 Mar 2023 20:59:26 +0100 Subject: [PATCH] gdb: fix commands formatting --- gdb/commands.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/gdb/commands.py b/gdb/commands.py index 9c69e2d..c015bb3 100644 --- a/gdb/commands.py +++ b/gdb/commands.py @@ -5,6 +5,13 @@ import gdb import time import re import json +import pwd +import grp +import stat +import time + +from datetime import datetime + class DumpMemory(gdb.Command): """Dump memory info into a file.""" @@ -41,8 +48,10 @@ class DumpMemory(gdb.Command): except Exception as e: print("Usage: dm [pattern]\n\twhith pattern : heap, stack or any value in /proc/self/maps") + DumpMemory() + class DumpJson(gdb.Command): """Dump std::string as a styled JSON.""" @@ -67,11 +76,14 @@ class DumpJson(gdb.Command): except Exception as e: print(f"Parse json error! {args}") + DumpJson() tp = {} + class Tracepoint(gdb.Breakpoint): + def __init__(self, *args): super().__init__(*args) self.silent = True @@ -99,7 +111,10 @@ class Tracepoint(gdb.Breakpoint): # do not stop at tracepoint return False + class SetTracepoint(gdb.Command): + """ Everytime the function in parameter get called, a message is printed with the argument used """ + def __init__(self): super().__init__("tp", gdb.COMMAND_USER) @@ -110,11 +125,13 @@ class SetTracepoint(gdb.Command): except Exception as e: print(e) + def finish(event): for t, p in tp.items(): c = p.count print(f"Tracepoint '{t}' Count: {c}") + gdb.events.exited.connect(finish) SetTracepoint() @@ -134,6 +151,7 @@ class EndPoint(gdb.FinishBreakpoint): print(f"\tCost: {diff}") return False + class StartPoint(gdb.Breakpoint): def __init__(self, *a, **kw): super().__init__(*a, **kw) @@ -170,7 +188,10 @@ class StartPoint(gdb.Breakpoint): EndPoint(self, internal=True) return False + class Profile(gdb.Command): + """ Profile execution time of a function """ + def __init__(self): super().__init__("prof", gdb.COMMAND_USER) @@ -180,19 +201,10 @@ class Profile(gdb.Command): except Exception as e: print(e) + Profile() - - -import pwd -import grp -import stat -import time - -from datetime import datetime - - class StatPrint: def __init__(self, val): self.val = val @@ -258,6 +270,8 @@ class StatPrint: out += f"Change: {self.get_time(st_ctim)}\n" out += "}" return out + + # Could be disabled at runtime with: # disable pretty-print global sp # then check "info pretty-print"