This is an archive of the discontinued LLVM Phabricator instance.

Add -s/--source option support (MI)
ClosedPublic

Authored by ki.stfu on Apr 25 2015, 11:24 PM.

Details

Summary

This patch adds -s/--source option to execute source file with prepared command.
For example:

$ cat start_script 
target create ~/p/hello
process launch -s
continue
$ bin/lldb-mi -s start_script 
(gdb)
target create ~/p/hello
Current executable set to '~/p/hello' (x86_64).
^done
(gdb)
process launch -s
=shlibs-added,shlib-info=[num="1",name="hello",dyld-addr="-",reason="dyld",path="/Users/IliaK/p/hello",loaded_addr="-",dsym-objpath="/Users/IliaK/p/hello.dSYM/Contents/Resources/DWARF/hello"]
Process 33289 launched: '/Users/IliaK/p/hello' (x86_64)
^done
(gdb)
continue
=thread-created,id="1",group-id="i1"
=thread-selected,id="1"
(gdb)
Process 33289 resuming
Process 33289 exited with status = 0 (0x00000000) 
^done

Diff Detail

Event Timeline

ki.stfu updated this revision to Diff 24437.Apr 25 2015, 11:24 PM
ki.stfu retitled this revision from to Add -s/--source option support (MI).
ki.stfu updated this object.
ki.stfu edited the test plan for this revision. (Show Details)
ki.stfu added a reviewer: abidh.
ki.stfu added subscribers: abidh, Unknown Object (MLST).
abidh edited edge metadata.Apr 27 2015, 4:00 AM

First of all, can you explain the use cases where this functionality will be useful. I can see that it may help with testing. But I dont see much use otherwise.

Patch looks ok apart from some inline comments. Also this patch is dependent on other patch that implements WaitForHandleEvent, so wait for that patch to be reviewed/committed.

tools/lldb-mi/MIDriver.cpp
554

As I informed you in another email, there are problem with sync mode. So should this be set to true.

1297

We dont want comments to be printed on sonsole so this check should be done before TextToStdout call.

1310

Please complete the comment.

In D9278#161869, @abidh wrote:

First of all, can you explain the use cases where this functionality will be useful. I can see that it may help with testing. But I dont see much use otherwise.

This option is very useful in case when IDE needs an extra efforts to setup debug session. For example, to debug remote platform we should select ios-remote first, then create a target for this platform and connect to remote debugserver. All these commands may be written to init.cmds file that should be passed to lldb-mi via --source option.

tools/lldb-mi/MIDriver.cpp
554

Yep. I remember about this problem but we really should execute prepared commands in sync mode, otherwise we can't do the following:

-file-exec-and-symbols ~/p/hello
^done
-break-insert -f main
^done
-exec-run
^running
-stack-list-arguments 1
^error,msg="invalid thread"
*stopped,reason="breakpoint-hit"

As you see, in async mode the *stopped notification comes after we have tried to execute -stack-list-arguments (what's wrong).

I'll look at *stopped in sync mode a bit later.

1297

It's a little workaround for lldb because it doesn't support the echo command (unlike gdb). Therefore to emulate this behavior I can add a comment in init.cmds that will be printed during execution.

1310

ops.

ki.stfu updated this revision to Diff 24465.Apr 27 2015, 5:03 AM
ki.stfu edited edge metadata.

Fix a comment and skip empty lines

This option is very useful in case when IDE needs an extra efforts to setup debug session. For example, to debug remote platform we should select ios-remote first, then create a target for this platform and connect to remote debugserver. All these commands may be written to init.cmds file that should be passed to lldb-mi via --source option.

What is the problem if those commands are sent normally instead of init.cmds. Would that not work? Eclipse sends a lot of other command before starting debugging. So it would seems a little unnecessary to me.

I am not opposed to the patch but I don't think that it solves any problem.

In D9278#162701, @abidh wrote:

This option is very useful in case when IDE needs an extra efforts to setup debug session. For example, to debug remote platform we should select ios-remote first, then create a target for this platform and connect to remote debugserver. All these commands may be written to init.cmds file that should be passed to lldb-mi via --source option.

What is the problem if those commands are sent normally instead of init.cmds. Would that not work? Eclipse sends a lot of other command before starting debugging. So it would seems a little unnecessary to me.

I am not opposed to the patch but I don't think that it solves any problem.

It just a new functionality that serves for execution of prepared commands from source file. Of course we can pass them by hand, but I'd prefer to pass prepared file as a --source arg instead of typing all of them by hand (or copy-pasting :)).

abidh added a comment.Apr 29 2015, 1:42 AM

It just a new functionality that serves for execution of prepared commands from source file. Of course we can pass them by hand, but I'd prefer to pass prepared file as a --source arg instead of typing all of them by hand (or copy-pasting :)).

I understand as I do a lot of testing by giving manual commands. But in the end, MI commands are not supposed to be given by hand. It is assumed that some front end IDE will use it where it should not be a problem to generate those commands.

As such I am not opposed to the patch but I think it will be adding a thing we don't really need. Once this code is in then we will have to maintain it and make sure that it keeps working as people can depend on that behaviour. If you still want it in then I will not stand in the way. Please go ahead and commit.

In D9278#163041, @abidh wrote:

It just a new functionality that serves for execution of prepared commands from source file. Of course we can pass them by hand, but I'd prefer to pass prepared file as a --source arg instead of typing all of them by hand (or copy-pasting :)).

I understand as I do a lot of testing by giving manual commands. But in the end, MI commands are not supposed to be given by hand. It is assumed that some front end IDE will use it where it should not be a problem to generate those commands.

As such I am not opposed to the patch but I think it will be adding a thing we don't really need. Once this code is in then we will have to maintain it and make sure that it keeps working as people can depend on that behaviour. If you still want it in then I will not stand in the way. Please go ahead and commit.

You are suggesting that there is a front-end that can pass these commands to lldb-mi, but it's not always true. For example, to test lldb-mi functionality on device I run lldb-mi with --source option and then grep the output to check my test cases. Of course I can write a simple front-end to read these commands from file and pass them to lldb-mi, but another way is just add --source support in lldb-mi like in lldb/gdb. So yes, I'm sure that it's needed.

abidh accepted this revision.May 1 2015, 1:57 AM
abidh edited edge metadata.
This revision is now accepted and ready to land.May 1 2015, 1:57 AM
ki.stfu closed this revision.May 6 2015, 11:55 PM
labath added a subscriber: labath.May 7 2015, 1:25 AM

These new tests have been failing on the linux build bot:

======================================================================
ERROR: test_lldbmi_source_option_start_script (TestMiStartupOptions.MiStartupOptionsTestCase)
    Test that 'lldb-mi --interpreter' can execute user's commands after initial commands were executed.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/lldb-buildbot/lldbSlave/buildWorkingDir/llvm/tools/lldb/test/lldbtest.py", line 447, in wrapper
    return func(self, *args, **kwargs)
  File "/lldb-buildbot/lldbSlave/buildWorkingDir/llvm/tools/lldb/test/lldbtest.py", line 562, in wrapper
    func(*args, **kwargs)
  File "/lldb-buildbot/lldbSlave/buildWorkingDir/llvm/tools/lldb/test/tools/lldb-mi/startup_options/TestMiStartupOptions.py", line 167, in test_lldbmi_source_option_start_script
    self.expect("\^done,value=\"10\"")
  File "/lldb-buildbot/lldbSlave/buildWorkingDir/llvm/tools/lldb/test/tools/lldb-mi/lldbmi_testcase.py", line 46, in expect
    return self.child.expect(pattern, *args, **kwargs)
  File "/lldb-buildbot/lldbSlave/buildWorkingDir/llvm/tools/lldb/test/pexpect-2.4/pexpect.py", line 1316, in expect
    return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
  File "/lldb-buildbot/lldbSlave/buildWorkingDir/llvm/tools/lldb/test/pexpect-2.4/pexpect.py", line 1330, in expect_list
    return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
  File "/lldb-buildbot/lldbSlave/buildWorkingDir/llvm/tools/lldb/test/pexpect-2.4/pexpect.py", line 1414, in expect_loop
    raise TIMEOUT (str(e) + '\n' + str(self))
TIMEOUT: Timeout exceeded in read_nonblocking().
<pexpect.spawn object at 0x7f440f6f0a10>
version: 2.4 ($Revision: 516 $)
command: /lldb-buildbot/lldbSlave/buildWorkingDir/build/bin/lldb-mi
args: ['/lldb-buildbot/lldbSlave/buildWorkingDir/build/bin/lldb-mi', '--interpreter', '--source', 'start_script']
searcher: searcher_re:
    0: re.compile("\^done,value="10"")
buffer (last 100 chars): 
-data-evaluate-expression a
^error,msg="Could not evaluate expression"

These new tests have been failing on the linux build bot:

Fixed by r236708.