2 ##===-- lui.py -----------------------------------------------*- Python -*-===##
4 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 # See https://llvm.org/LICENSE.txt for license information.
6 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 ##===----------------------------------------------------------------------===##
16 from optparse
import OptionParser
38 def handle_args(driver
, argv
):
39 parser
= OptionParser()
41 "-p", "--attach", dest
="pid", help="Attach to specified Process ID", type="int"
44 "-c", "--core", dest
="core", help="Load specified core file", type="string"
47 (options
, args
) = parser
.parse_args(argv
)
49 if options
.pid
is not None:
51 pid
= int(options
.pid
)
52 driver
.attachProcess(ui
, pid
)
54 print("Error: expecting integer PID, got '%s'" % options
.pid
)
55 elif options
.core
is not None:
56 if not os
.path
.exists(options
.core
):
57 raise Exception("Specified core file '%s' does not exist." % options
.core
)
58 driver
.loadCore(options
.core
)
60 if not os
.path
.isfile(args
[1]):
61 raise Exception("Specified target '%s' does not exist" % args
[1])
62 driver
.createTarget(args
[1])
64 if not os
.path
.isfile(args
[1]):
65 raise Exception("Specified target '%s' does not exist" % args
[1])
66 driver
.createTarget(args
[1], args
[2:])
69 def sigint_handler(signal
, frame
):
74 class LLDBUI(cui
.CursesUI
):
75 def __init__(self
, screen
, event_queue
, driver
):
76 super(LLDBUI
, self
).__init
__(screen
, event_queue
)
80 h
, w
= self
.screen
.getmaxyx()
82 command_win_height
= 20
85 self
.status_win
= statuswin
.StatusWin(0, h
- 1, w
, 1)
87 self
.command_win
= commandwin
.CommandWin(
88 driver
, 0, h
- command_win_height
, w
, command_win_height
90 h
-= command_win_height
91 self
.source_win
= sourcewin
.SourceWin(driver
, 0, 0, w
- break_win_width
- 1, h
)
92 self
.break_win
= breakwin
.BreakWin(
93 driver
, w
- break_win_width
, 0, break_win_width
, h
104 self
.focus
= len(self
.wins
) - 1 # index of command window;
106 def handleEvent(self
, event
):
108 if isinstance(event
, int):
109 if event
== curses
.KEY_F10
:
110 self
.driver
.terminate()
111 if event
== 20: # ctrl-T
114 ret
= lldb
.SBCommandReturnObject()
115 self
.driver
.getCommandInterpreter().HandleCommand(cmd
, ret
)
117 foo("target create a.out")
120 super(LLDBUI
, self
).handleEvent(event
)
124 signal
.signal(signal
.SIGINT
, sigint_handler
)
127 event_queue
= queue
.Queue()
130 debugger
= lldb
.SBDebugger
.Create()
132 driver
= debuggerdriver
.createDriver(debugger
, event_queue
)
133 view
= LLDBUI(screen
, event_queue
, driver
)
137 # hack to avoid hanging waiting for prompts!
138 driver
.handleCommand("settings set auto-confirm true")
140 handle_args(driver
, sys
.argv
)
144 if __name__
== "__main__":
147 except KeyboardInterrupt: