Commit Graph

40 Commits

Author SHA1 Message Date
Ilia K b2b0170c0e Allow to construct CMIUtilString using std::string directly + cleanup CMIUtilString (MI)
Summary:
Allow to construct CMIUtilString using std::string directly + cleanup CMIUtilString (MI)

This patch cleans up lldb-mi code, and serves to simplify
the following case:
```
  std::string strGoodbye = "!Hello";
  CMIUtilString strHello(strGoodbye.substr(1).c_str());
```

With CMIUtilString(std::string) we can omit .c_str():
```
  std::string strGoodbye = "!Hello";
  CMIUtilString strHello(strGoodbye.substr(1));
```

Also, it removes 2 ctors because they aren't needed:
# CMIUtilString::CMIUtilString(const char *const *vpData)
# CMIUtilString::CMIUtilString(const char *vpData, size_t nLen)
and cleans up CMIUtilString::operator=(const std::string &vrRhs).

Reviewers: brucem, abidh

Subscribers: lldb-commits, brucem, abidh

Differential Revision: http://reviews.llvm.org/D13158

llvm-svn: 248566
2015-09-25 08:28:58 +00:00
Bruce Mitchener e2453afff6 [lldb-mi] Use empty arg lists instead of (void).
Summary: This brings the code more in line with the usual LLDB style. NFC.

Reviewers: abidh, ki.stfu

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D11746

llvm-svn: 243967
2015-08-04 10:24:20 +00:00
Dawn Perchik 6145ad2d36 [lldb-mi] Add const qualifier to vMITextLine in InterpretCommandThisDriver.
llvm-svn: 242057
2015-07-13 20:16:13 +00:00
Bruce Mitchener ae4c026765 [lldb-mi] Fix typos
llvm-svn: 241585
2015-07-07 14:04:40 +00:00
Bruce Mitchener e86c6fa3dc [lldb-mi] Use size_t where appropriate.
Summary:
Many places should have been using size_t rather than MIuint or
MIint. This is particularly true for code that uses std::string::find(),
std::string::rfind(), std::string::size(), and related methods.

Reviewers: abidh, ki.stfu, domipheus

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D10931

llvm-svn: 241360
2015-07-03 15:40:44 +00:00
Bruce Mitchener 3b25b479bf Remove typedefs for MIchar, MIschar, MIuchar.
Summary:
This is a start on bringing lldb-mi more in line with the typical
LLDB coding style. This just removes the usage of the typedefs and
doesn't yet clean up any logic or other issues. (This is to keep
the review simple.)

Reviewers: abidh, ki.stfu, domipheus

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D10917

llvm-svn: 241349
2015-07-03 13:45:34 +00:00
Bruce Mitchener 58ef391f3e Fix a variety of typos.
No functional change.

llvm-svn: 239995
2015-06-18 05:27:05 +00:00
Dawn Perchik 86e90b3cfa Fix comments (MI).
llvm-svn: 239861
2015-06-16 22:53:27 +00:00
Ilia K 38810f430b Fix handling of hijacked events in synchronous mode
Summary:
This patch includes the following changes:
* Fix Target::Launch to handle hijacked event in synchronous mode
* Improve MiStartupOptionsTestCase tests to expect *stopped (MI)
* Add SBProcess::GetStopEventForStopID
* Add ProcessModID::SetStopEventForLastNaturalStopID/GetStopEventForStopID
* Add const qualifier to ProcessModID::GetLastNaturalStopID
* Add SBProcess::GetStopEventForStopID
* Don't broadcast hijacked event in Target::Launch
* Add CMICmnLLDBDebugger::CheckIfNeedToRebroadcastStopEvent/RebroadcastStopEvent

Test Plan: ./dotest.py -v --executable $BUILDDIR/bin/lldb tools/lldb-mi/startup_options/

Reviewers: zturner, jingham, clayborg, abidh

Reviewed By: clayborg

Subscribers: abidh, zturner, lldb-commits, clayborg, jingham

Differential Revision: http://reviews.llvm.org/D9371

llvm-svn: 237781
2015-05-20 10:15:47 +00:00
Ilia K 0e919bca7f Refactor lldb-mi's prompt
Summary:
This patch fixes/cleans code around of (gdb) prompt:
# Add CMICmnStreamStdout::WritePrompt
# Clean up CMICmnStreamStdout::TextToStdout (don't lock
  the m_mutex twice because it will be locked in CMICmnStreamStdout::WritePriv)
# Remove unused CMICmnStreamStdin::m_bShowPrompt field
# Refactor CMICmnLLDBDebuggerHandleEvents to use CMICmnStreamStdout::WritePrompt
  instead of TextToStdout("(gdb)")
# Refactor CMIDriver to use CMICmnStreamStdout::WritePrompt instead of
  ```
    if (bOk && m_rStdin.GetEnablePrompt())
        bOk = m_rStdOut.WriteMIResponse(m_rStdin.GetPrompt());
  ```

Test Plan: ./dotest.py -v --executable $BUILDDIR/bin/lldb tools/lldb-mi/

Reviewers: abidh

Reviewed By: abidh

Subscribers: lldb-commits, abidh

Differential Revision: http://reviews.llvm.org/D9737

llvm-svn: 237248
2015-05-13 12:18:20 +00:00
Ilia K d3da77e84e Add -s/--source option support (MI)
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
```

Test Plan: ./dotest.py -v --executable $BUILDDIR/bin/lldb tools/lldb-mi/

Reviewers: abidh

Reviewed By: abidh

Subscribers: lldb-commits, abidh

Differential Revision: http://reviews.llvm.org/D9278

llvm-svn: 236703
2015-05-07 06:51:46 +00:00
Ilia K 8913012ee9 Remove quit hook in CMIDriver::DoMainLoop (MI)
Summary:
This patch removes quit hook and fixes 1 bug:
# Fix "quit" hook in CMIDriver::DoMainLoop (MI)
# Fix bug when the handler thread exits without any notification (MI)
# Fix a race condition in CMICmnLLDBDebugger::MonitorSBListenerEvents (MI)

Test Plan: ./dotest.py -v --executable $BUILDDIR/bin/lldb tools/lldb-mi/

Reviewers: abidh

Reviewed By: abidh

Subscribers: lldb-commits, abidh

Differential Revision: http://reviews.llvm.org/D9275

llvm-svn: 236702
2015-05-07 06:45:42 +00:00
Ilia K b64b8e16db Clean the CMIDriver (MI)
This patch does the following things:
* Use CMICmnStreamStdout::TextToStdout to print (gdb) prompt in CMIDriver::InitClientIDEEclipse
* Remove unnecessary inclusions

llvm-svn: 235817
2015-04-26 05:55:59 +00:00
Ilia K bc929b80dc Fix handling of the executable arg which contains spaces (MI)
* Don't use the CMICmdArgValFile::GetFileNamePath for the CMIDriver::m_strCmdLineArgExecuteableFileNamePath
  because it wraps path with spaces into quotes what is already being done in CMIDriver::LocalDebugSessionStartupExecuteCommands
* Improve the MiSyntaxTestCase.test_lldbmi_specialchars test to catch this error
  ```
    $ bin/lldb-mi "~/p/ hello"
    (gdb)
    -file-exec-and-symbols "\"~/p/ hello\""
    ^error,msg="Command 'file-exec-and-symbols'. Target binary '\"~/p/ hello\"' is invalid. error: unable to find executable for '/"~/p/ hello/"'"
  ```

llvm-svn: 234888
2015-04-14 14:12:22 +00:00
Ilia K 689dda1c67 Add support for CLI commands in lldb-mi
Summary:
This patch adds support for CLI command in lldb-mi. It's useful ability which also was implemented in gdb.

All tests pass on OS X.

Test Plan: ./dotest.py -v --executable $BUILDDIR/bin/lldb tools/lldb-mi/interpreter/

Reviewers: ted, clayborg, abidh

Reviewed By: clayborg, abidh

Subscribers: jingham, lldb-commits, ted, clayborg, abidh

Differential Revision: http://reviews.llvm.org/D8483

llvm-svn: 233112
2015-03-24 20:59:38 +00:00
Hafiz Abid Qadeer 112b2622df Remove redundant code from lldb-mi.
After removing the ability of using lldb-mi as 'lldb', a lot of code has become redundant. This commit removes some of that code.
Note: Some files are being removed. The cmake file has been updated. Please update xcode project accordingly.

llvm-svn: 233083
2015-03-24 14:07:25 +00:00
Ilia K aa27aadb14 Fix double (gdb) prompt when command doesn't exist
llvm-svn: 232715
2015-03-19 09:17:06 +00:00
Ilia K 30a4ba1721 Fix error handling in CMIDriver::DoMainLoop after r215223 (MI)
llvm-svn: 232713
2015-03-19 08:54:17 +00:00
Ilia K 5d8b145d70 Fix comment in tools/lldb-mi/MIDriver.cpp
llvm-svn: 232633
2015-03-18 13:08:52 +00:00
Hafiz Abid Qadeer 4a7baeab14 Make lldb-mi handle only MI commands
Summary:
Previously lldb-mi can also act as a driver like normal lldb. It needed a lot
of redundant code in the lldb-mi for that. I think that if a user wants command
line lldb driver then he/she should use the lldb for it. This change will cleanup
the code a lot. When this change goes in, it will allow us to remove some more
redundant code too.

All tests pass on Linux. Did some sanity testing on command line and with eclipse.

Reviewers: ki.stfu

Reviewed By: ki.stfu

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D8381

llvm-svn: 232621
2015-03-18 10:07:46 +00:00
Hafiz Abid Qadeer a40780e36c Remove redundant comments from lldb-mi source files.
Most of lldb-mi files have comments about environement, copyright etc which were neither needed nor uptodate.
This commit removes those comments.

llvm-svn: 232396
2015-03-16 18:18:18 +00:00
Ilia K c6c716ac9d Allow to pass an executable file via lldb-mi arguments (MI)
Summary:
# Allow to pass an executable file via lldb-mi arguments
# Add tests
# Fix (gdb) prompt in CMIDriver::LocalDebugSessionStartupExecuteCommands
# Fix prompt in CMIDriver::InterpretCommandThisDriver: use the lldb-mi prompt instead of a hard-coded value.

All tests pass on OS X.

Reviewers: abidh, clayborg

Reviewed By: clayborg

Subscribers: lldb-commits, clayborg, abidh

Differential Revision: http://reviews.llvm.org/D8001

llvm-svn: 231070
2015-03-03 15:14:32 +00:00
Ilia K f1115fe0c5 Rename CMIDriver::LocalDebugSessionStartupInjectCommands to CMIDriver::LocalDebugSessionStartupExecuteCommands after r230003
llvm-svn: 230944
2015-03-02 10:58:02 +00:00
Ilia K 69b95f49f1 Fix handling of double quotes (MI)
Summary:
* Clean CMICmdArgValString::Validate: now it's based on CMIUtilString::SplitConsiderQuotes method:
A bit of introduction:
# Command line is wrapped into CMICmdArgContext.
# CMICmdArgSet is a set of arguments to be parsed. This class contains CMICmdArgContext as a private member.
# MI command is class which is inhereted from CMICmdBase. It contains CMICmdArgSet as a private member.

When command is executed CMICmdBase::ParseArgs() is called. This method adds args for parsing using CMICmdArgSet::Add(). Then CMICmdBase::ParseValidateCmdOptions() is called, which calls CMICmdArgSet::Validate(). Then it gets a number of arguments (using SplitConsiderQuotes().array_length) and for each arguments registered in ParseArgs() tries to validate it using CMICmdArgValBase::Validate(). Every user commands parses this string again (first time it was made in SplitConsiderQuotes) and in case of CMICmdArgValString it was made incorrectly. It searches the first and last quotes (but it should be first and next after first). Besides, it was splitted into 4 cases. 
I'm just using SplitConsiderQuotes directly, and I don't split them by hand again. 

Actually, I think we should do so in every CMICmdArgVal_XXX::Validate() method.

* Enable MiInterpreterExecTestCase.test_lldbmi_target_create test
* Fix MiExecTestCase.test_lldbmi_exec_arguments_set test

All tests pass on OS X.

Reviewers: abidh, emaste, zturner, clayborg

Reviewed By: clayborg

Subscribers: lldb-commits, zturner, emaste, clayborg, abidh

Differential Revision: http://reviews.llvm.org/D7860

llvm-svn: 230654
2015-02-26 18:21:22 +00:00
Hafiz Abid Qadeer 04b1b5dc9d Remove redundant code from lldb-mi.
Summary:
After recent changes, some code has become redundant. This revision tries to remove
the un-used code and tidy up the rest.

Following 4 files have been removed. I have updated CMake files and checked that it builds
fine on Linux and Windows. Can somebody update the xcode related file accordingly?

tools/lldb-mi/MICmnStreamStdinLinux.cpp
tools/lldb-mi/MICmnStreamStdinLinux.h
tools/lldb-mi/MICmnStreamStdinWindows.cpp
tools/lldb-mi/MICmnStreamStdinWindows.h

Reviewers: clayborg, ki.stfu

Reviewed By: clayborg, ki.stfu

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D7834

llvm-svn: 230345
2015-02-24 17:08:20 +00:00
Hafiz Abid Qadeer 6d87a9c09e Reduce number of threads in lldb-mi.
LLDB-mi have 3 threads.

1. Wait for input.
2. Process commands.
3. Process events.
This revision merges 1 & 2. Same thread waits on input and then process the
command. This way, no synchronization is needed between first and 2nd. Also it is
easy to check when to exit.

A lot of code will redundant and will be cleaned up gradually.

All lldb-mi tests pass with gcc and clang as test compiler. Also did minimal testing
on command line and works ok. The "quit" and "-gdb-exit" command close the application
without needing any further return.

Reviewed in http://reviews.llvm.org/D7746.

llvm-svn: 230003
2015-02-20 10:20:05 +00:00
Ilia K a4897fe79c Add missing prompt when command doesn't exist (MI)
It fixes the following example:
```
$ bin/lldb-mi --interpreter
(gdb)
-not-found
^error,msg="Driver. Received command '-not-found'. It was not handled. Command 'not-found' not in Command Factory"
-not-found
^error,msg="Driver. Received command '-not-found'. It was not handled. Command 'not-found' not in Command Factory"
```

After the fix it looks like:
```
$ bin/lldb-mi --interpreter
-not-found
^error,msg="Driver. Received command '-not-found'. It was not handled. Command 'not-found' not in Command Factory"
(gdb)
-not-dounf
^error,msg="Driver. Received command '-not-dounf'. It was not handled. Command 'not-dounf' not in Command Factory"
(gdb)
```

llvm-svn: 229131
2015-02-13 18:36:48 +00:00
Hafiz Abid Qadeer d1f606ff0f Fix a race condition in lldb-mi.
lldb-mi has 3 threads.
1. One that waits for user intput.
2. Another waits for 1st thread to get input command.
3. Waits for events from lldb.

2 & 3 needs to be synchronized so that they don't end up
doing things at same time. For example, while "break insert" is
processing, we can get a breakpoint event. Depending on where we
are in "break-insert", it can have different behavior. In some
cases, it can cause breakpoint to be deleted too. I have added a 
mutex so that command processing and event processing are done 
exclusively and they are not running at the same time.

In longer term, I think thread 2 & 3 should be merged to be only 
one thread which can wait on command or events.

Reviewed in http://reviews.llvm.org/D7371.

llvm-svn: 228128
2015-02-04 09:59:23 +00:00
Greg Clayton ee3626ec16 Added an Xcode target so we build the "lldb-mi" executable as part of the "desktop" and "desktop no xpc" targets.
Include paths were switched to be user include paths, if this breaks the linux build we will need to fix the Makefiles/cmake stuff.

<rdar://problem/19198581> 

llvm-svn: 226530
2015-01-20 00:04:26 +00:00
Hafiz Abid Qadeer fcbc3cdf3c Replace ioctl with select to reduce processor usage by lldb-mi on OSX.
This saga started with a hang on OSX. 2 solutions were proposed.
1) 'select' based solution works ok on OSX but slows down test completion time
on Linux many times.
2) 'ioctl' base solution also works but it causes heavy processor usage on OSX
as reported by Ilia K.

But as the original hang did not occur on Linux so this commit re-introduces the
'select' in conditional code so that it only runs for OSX. There is no need for
this 'fix' to run on Linux.

Initial patch by Ilia K <ki.stfu@gmail.com>. A few changes were made by me. 

llvm-svn: 224258
2014-12-15 19:09:40 +00:00
Hafiz Abid Qadeer afd188fee4 Remove unnecessary changes committed in r223222.
There were 2 different patches in discussion. One using ioctl
and other using select. We decided to use the ioctl but committed
code also have some changes which were only needed for 'select'.
This patch removes them.

llvm-svn: 223227
2014-12-03 12:48:19 +00:00
Hafiz Abid Qadeer 25383ac01b Fix a hang on OSX while executing -exec-run.
Now we wait for input to become available before blocking in fgets.
More details on problem can be found in 
http://lists.cs.uiuc.edu/pipermail/lldb-commits/Week-of-Mon-20141201/014290.html

Patch from dawn@burble.org.

llvm-svn: 223222
2014-12-03 10:23:06 +00:00
Zachary Turner 1d6af02e2d Reformat lldb-mi using clang-format.
Courtesy of dawn@burble.org.

llvm-svn: 222150
2014-11-17 18:06:21 +00:00
Eric Christopher fa0f79207c Remove a pair of default values from fully covered switches.
llvm-svn: 217424
2014-09-09 06:35:14 +00:00
Deepak Panickal 7f6edd52c9 Restore some reverted fixes for spelling, newlines and __linux__ macro.
llvm-svn: 215234
2014-08-08 17:39:47 +00:00
Deepak Panickal d249928b84 Add new MI commands, features and fixes to the lldb-mi driver.
- Can now load an executable directly as an argument.
- Fixes towards supporting local debugging.
- Fixes for stack-list-arguments, data-evaluate-expression, environment-cd, stack-list-locals, interpreter-exec.
- Fix breakpoint event handling.
- Support dynamic loading of libraries using the search paths provided by Eclipse.

llvm-svn: 215223
2014-08-08 16:47:42 +00:00
Bruce Mitchener 6a7f33387d Fix a few typos.
llvm-svn: 211851
2014-06-27 02:42:12 +00:00
Deepak Panickal 877569c2b8 Added support for new MI commands and bug fixes. More details in MIReadme.txt.
llvm-svn: 211607
2014-06-24 16:35:50 +00:00
Sylvestre Ledru 88e68cdc94 Remove useless declaration
llvm-svn: 211451
2014-06-21 23:47:20 +00:00
Deepak Panickal 6f9c468102 Initial commit of LLDB Machine Interface Frontend.
- Tested with Eclipse, likely to work with other GDB/MI compatible GUIs.
- Some but not all MI commands have been implemented. See MIReadme.txt for more info.
- Written from scratch, no GPL code, based on LLDB Public API.
- Built for Linux, Windows and OSX. Tested on Linux and Windows.
- GDB/MI Command Reference, https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI.html

llvm-svn: 208972
2014-05-16 10:51:01 +00:00