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()
44 help="Attach to specified Process ID",
50 help="Load specified core file",
53 (options
, args
) = parser
.parse_args(argv
)
55 if options
.pid
is not None:
57 pid
= int(options
.pid
)
58 driver
.attachProcess(ui
, pid
)
60 print("Error: expecting integer PID, got '%s'" % options
.pid
)
61 elif options
.core
is not None:
62 if not os
.path
.exists(options
.core
):
64 "Specified core file '%s' does not exist." %
66 driver
.loadCore(options
.core
)
68 if not os
.path
.isfile(args
[1]):
69 raise Exception("Specified target '%s' does not exist" % args
[1])
70 driver
.createTarget(args
[1])
72 if not os
.path
.isfile(args
[1]):
73 raise Exception("Specified target '%s' does not exist" % args
[1])
74 driver
.createTarget(args
[1], args
[2:])
77 def sigint_handler(signal
, frame
):
82 class LLDBUI(cui
.CursesUI
):
84 def __init__(self
, screen
, event_queue
, driver
):
85 super(LLDBUI
, self
).__init
__(screen
, event_queue
)
89 h
, w
= self
.screen
.getmaxyx()
91 command_win_height
= 20
94 self
.status_win
= statuswin
.StatusWin(0, h
- 1, w
, 1)
96 self
.command_win
= commandwin
.CommandWin(
97 driver
, 0, h
- command_win_height
, w
, command_win_height
)
98 h
-= command_win_height
99 self
.source_win
= sourcewin
.SourceWin(driver
, 0, 0,
100 w
- break_win_width
- 1, h
)
101 self
.break_win
= breakwin
.BreakWin(driver
, w
- break_win_width
, 0,
104 self
.wins
= [self
.status_win
,
111 self
.focus
= len(self
.wins
) - 1 # index of command window;
113 def handleEvent(self
, event
):
115 if isinstance(event
, int):
116 if event
== curses
.KEY_F10
:
117 self
.driver
.terminate()
118 if event
== 20: # ctrl-T
120 ret
= lldb
.SBCommandReturnObject()
121 self
.driver
.getCommandInterpreter().HandleCommand(cmd
, ret
)
122 foo('target create a.out')
125 super(LLDBUI
, self
).handleEvent(event
)
129 signal
.signal(signal
.SIGINT
, sigint_handler
)
132 event_queue
= queue
.Queue()
135 debugger
= lldb
.SBDebugger
.Create()
137 driver
= debuggerdriver
.createDriver(debugger
, event_queue
)
138 view
= LLDBUI(screen
, event_queue
, driver
)
142 # hack to avoid hanging waiting for prompts!
143 driver
.handleCommand("settings set auto-confirm true")
145 handle_args(driver
, sys
.argv
)
148 if __name__
== "__main__":
151 except KeyboardInterrupt: