<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jul 18, 2019, at 4:00 AM, Jayvee Neumann <<a href="mailto:jayvee.neumann@gmail.com" class="">jayvee.neumann@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:monospace,monospace">Thank you for your help.</div><div class="gmail_default" style="font-family:monospace,monospace"><br class=""></div><div class="gmail_default" style="font-family:monospace,monospace">What is the reason for using SBLaunchInfo over calling tgt.Launch with the launch configuration as a set of parameters? </div></div></div></blockquote><div><br class=""></div><div>The code is much clearer on what arguments mean what. In your current launch call, it is hard to know what all arguments mean and would be easy to put</div><div><br class=""></div><div><div style="font-family: monospace, monospace; margin-left: 40px;" class="">SBProcess proc = tgt.Launch(<br class=""></div><div style="font-family: monospace, monospace; margin-left: 80px;" class="">listen,<br class="">nullptr,<br class="">nullptr,<br class="">nullptr,<br class="">"targetout.txt",<br class="">nullptr,<br class="">"./",<br class="">eLaunchFlagExec | eLaunchFlagDebug,<br class="">false,<br class="">error<br class=""></div><div class="gmail_default" style="font-family: monospace, monospace; margin-left: 40px;">);</div><div class="gmail_default" style="font-family: monospace, monospace; margin-left: 40px;"><br class=""></div><div class="gmail_default" style="font-family: monospace, monospace; margin-left: 40px;"><br class=""></div></div>New code:</div><div><br class=""></div><div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class=""><span style="color: #326d74" class="">SBError</span> error;</div></div><div><span style="font-family: monospace, monospace;" class="">SBListener </span><span style="font-family: monospace, monospace;" class="">listen</span><span style="font-family: monospace, monospace;" class="">;</span></div><div><span style="font-family: monospace, monospace;" class="">const char **argv[] = { "arg1", "arg2" };</span></div><div>SBLaunchInfo launch_info(<span style="font-family: monospace, monospace;" class="">argv</span>);</div><div>launch_info.<span style="background-color: rgb(255, 255, 255);" class="">SetListener(</span><span style="font-family: monospace, monospace;" class="">listen</span><span style="background-color: rgb(255, 255, 255);" class="">);</span></div><div>launch_info.<span style="background-color: rgb(255, 255, 255);" class="">SetWorkingDirectory(getcwd());</span></div><div>launch_info.<span style="background-color: rgb(255, 255, 255);" class="">AddOpenFileAction(<font color="#9b2393" class=""><span style="caret-color: rgb(155, 35, 147);" class=""><b class="">STDOUT_FILENO</b></span></font></span><span style="background-color: rgb(255, 255, 255);" class="">,<font color="#9b2393" class=""><span style="caret-color: rgb(155, 35, 147);" class=""><b class="">"</b></span></font></span><span style="font-family: monospace, monospace;" class="">targetout.txt", false</span><span style="background-color: rgb(255, 255, 255);" class="">, <font color="#9b2393" class=""><span style="caret-color: rgb(155, 35, 147);" class=""><b class="">true</b></span></font></span><span style="background-color: rgb(255, 255, 255);" class="">);</span></div><div>launch_info.<span style="background-color: rgb(255, 255, 255);" class="">SetLaunchFlags(</span><span style="font-family: monospace, monospace;" class="">eLaunchFlagExec | eLaunchFlagDebug);</span></div><div><span style="font-family: monospace, monospace;" class="">SBProcess proc = tgt.Launch(info, </span><span style="background-color: rgb(255, 255, 255);" class="">error</span><span style="font-family: monospace, monospace;" class="">);</span></div><div><span style="font-family: monospace, monospace;" class=""><br class=""></span></div><div><span style="font-family: monospace, monospace;" class="">You can see what each argument means above a bit more clearly. This also means you can create a SBLaunchInfo object before parsing the options, and using the options you could lazily populate the launch info object, then use it to launch.</span></div><div><span style="font-family: monospace, monospace;" class=""><br class=""></span></div><div><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:monospace,monospace">Furthermore I do not see a way to set stdout, stdin, and stderr for the launched process by using SBLaunchInfo.<br class=""></div></div></div></blockquote><div><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class=""> <span style="color: #9b2393" class=""><b class="">bool</b></span> SBLaunchInfo::AddOpenFileAction(<span style="color: #9b2393" class=""><b class="">int</b></span> fd, <span style="color: #9b2393" class=""><b class="">const</b></span> <span style="color: #9b2393" class=""><b class="">char</b></span> *path, <span style="color: #9b2393" class=""><b class="">bool</b></span> read, <span style="color: #9b2393" class=""><b class="">bool</b></span> write);</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:monospace,monospace"><br class=""></div><div class="gmail_default" style="font-family:monospace,monospace">I have a question regarding the event loop.</div><div class="gmail_default" style="font-family:monospace,monospace">Is lldb thread-safe enough such that I can run that loop in another std::thread while simultaneously using other debugger functions?</div></div></div></blockquote><div><br class=""></div>Yes you can. I would suggest being careful though as you wouldn't want to try and display variables from a current frame while another thread is resuming the process. The code will work, but some calls might fail when the process does resume. We usually run a thread that listens for events, and when handling these events, it might do things like display all local variables in the IDE when a eStateStopped event is detected.</div><div><br class=""></div><div>Some IDEs maintain a stack of work items to do. Say the user hits step 5 times really quickly by pressing F11 5 times, it is a good idea to make a queue of things to do for the debugger, and the stack now contains 5 "step over" commands. The IDE in the event loop will wait for the process to stop, check the command queue, and if there is another command in there, it could skip displaying the variables and updating all of the views and instead just pop one of the "step over" commands from the queue and do that. Once you stop and the queue is empty, you can show variables and stack traces, etc. Also, you might implement a timeout of .5 seconds after a stop before you show the variables in case the user continues or steps again really quickly. The user might also hit step a bunch of times and then click stop. Some IDEs flush the command queue to ensure we stop when the user hits the stop button to ensure we don't keep stepping too long. </div><div><br class=""></div><div>So just be careful to think about the logic you want. If you stop your process, it is a good idea to grab the variables and get their values on the same thread that is controlling the process so you don't end up with your variable view trying to display variables as the process resumes. It is also a good idea to take the user input (step, continue, kill) and queue them up and consume those events in your event loop.</div><div><br class=""></div><div>Let me know if that makes sense,</div><div><br class=""></div><div>Greg Clayton</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:monospace,monospace"><br class=""></div><div class="gmail_default" style="font-family:monospace,monospace">Kind regards,</div><div class="gmail_default" style="font-family:monospace,monospace">Jayvee<br class=""></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Fr., 12. Juli 2019 um 19:56 Uhr schrieb Greg Clayton <<a href="mailto:clayborg@gmail.com" class="">clayborg@gmail.com</a>>:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;" class="">You need to call SBDebugger::Initialize() before calling SBDebugger::Create().<div class=""><br class=""></div><div class="">Also, please use the <span style="background-color:rgb(255,255,255)" class="">SBLaunchInfo</span> method for launching if possible where you create a <span style="background-color:rgb(255,255,255)" class="">SBLaunchInfo, then call tgt.Launch() with the instance.</span></div><div class=""><span style="background-color:rgb(255,255,255)" class=""><br class=""></span></div><div class=""><span style="background-color:rgb(255,255,255)" class="">Other than that, as Jim said, you need to setup an event loop if you don't use synchronous mode where you wait for events and respond to events. </span></div><div class=""><span style="background-color:rgb(255,255,255)" class=""><br class=""></span></div><div class=""><span style="background-color:rgb(255,255,255)" class="">Greg<br class=""></span><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Jun 26, 2019, at 4:58 AM, Jayvee Neumann via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org" target="_blank" class="">lldb-dev@lists.llvm.org</a>> wrote:</div><br class="gmail-m_5136867598933145329Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:monospace,monospace">Dear LLDB developers,</div><div class="gmail_default" style="font-family:monospace,monospace"><br class=""></div><div class="gmail_default" style="font-family:monospace,monospace">I am currently stuck while using the C++ API of LLDB. I am unable to correctly launch a process.</div><div class="gmail_default" style="font-family:monospace,monospace">The code I have written looks as follows:</div><div class="gmail_default" style="font-family:monospace,monospace"><br class="">int main(int argc, char *argv[]){<br class=""><div style="margin-left:40px" class=""> LLDBSentry senty;<br class=""> SBDebugger dbg(SBDebugger::Create());<br class=""> ...<br class=""> const char *exeFilePath = "./target";<br class=""> const char *arch = "x86_64";<br class=""> const char *platform = "";<br class=""> const char *dependentLibs = ""; <br class=""> SBError error;<br class=""> SBTarget tgt = dbg.CreateTarget(exeFilePath, arch, platform, dependentLibs, error);<br class=""> ...<br class=""> SBListener listen;<br class=""> SBProcess proc = tgt.Launch(<br class=""></div><div style="margin-left:80px" class=""> listen,<br class=""> nullptr,<br class=""> nullptr,<br class=""> nullptr,<br class=""> "targetout.txt",<br class=""> nullptr,<br class=""> "./",<br class=""> eLaunchFlagExec | eLaunchFlagDebug,<br class=""> false,<br class=""> error<br class=""></div><div class="gmail_default" style="font-family:monospace,monospace;margin-left:40px"> );<br class="">...<br class=""> SBThread thread = proc.GetSelectedThread(); // (1)<br class=""></div></div><div class="gmail_default" style="font-family:monospace,monospace;margin-left:40px">...</div><div class="gmail_default" style="font-family:monospace,monospace">}</div><div class="gmail_default" style="font-family:monospace,monospace"><br class=""></div><div class="gmail_default" style="font-family:monospace,monospace">The complete code (usr.cpp) is added as an attachment to this email.</div><div class="gmail_default" style="font-family:monospace,monospace">Its output is also added as a text file (stdout.txt) to this email.</div><div class="gmail_default" style="font-family:monospace,monospace"><br class=""></div><div class="gmail_default" style="font-family:monospace,monospace">The problem I have is, that thread.IsValid() returns null after line (1). Furthermore, the process says, that its state is eStateStopped, when asked via proc.IsStopped() it answers "false", however.<br class=""></div><div class="gmail_default" style="font-family:monospace,monospace">The debugging target is a simple file that writes a hexadecimal number every 10us to stdout. I can see that the target is running, because targetout.txt is growing in size and its content is valid output from "target".</div><div class="gmail_default" style="font-family:monospace,monospace">Can you tell me what my mistake is?</div><div class="gmail_default" style="font-family:monospace,monospace"><br class=""></div><div class="gmail_default" style="font-family:monospace,monospace">Kind Regards</div><div class="gmail_default" style="font-family:monospace,monospace">Jayvee<br class=""></div><div class="gmail_default" style="font-family:monospace,monospace"><br class=""></div></div>
<span id="gmail-m_5136867598933145329cid:f_jxd4t7do1" class=""><usr.cpp></span><span id="gmail-m_5136867598933145329cid:f_jxd4t7df0" class=""><stdout.txt></span>_______________________________________________<br class="">lldb-dev mailing list<br class=""><a href="mailto:lldb-dev@lists.llvm.org" target="_blank" class="">lldb-dev@lists.llvm.org</a><br class=""><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" target="_blank" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br class=""></div></blockquote></div><br class=""></div></div></blockquote></div>
</div></blockquote></div><br class=""></body></html>