[Lldb-commits] [lldb] r207568 - Added gdb remote protocol tests for no output and inferior non-zero exit code.
Todd Fiala
todd.fiala at gmail.com
Tue Apr 29 11:21:07 PDT 2014
Author: tfiala
Date: Tue Apr 29 13:21:07 2014
New Revision: 207568
URL: http://llvm.org/viewvc/llvm-project?rev=207568&view=rev
Log:
Added gdb remote protocol tests for no output and inferior non-zero exit code.
Tests added for debugserver and lldb-gdbserver. lldb-gdbserver marked as
XFAIL on top of tree.
Added build_gdbremote_A_packet test helper to construct a gdbremote A
launch packet from a list of args.
Modified:
lldb/trunk/test/tools/lldb-gdbserver/TestLldbGdbServer.py
lldb/trunk/test/tools/lldb-gdbserver/lldbgdbserverutils.py
lldb/trunk/test/tools/lldb-gdbserver/main.cpp
Modified: lldb/trunk/test/tools/lldb-gdbserver/TestLldbGdbServer.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-gdbserver/TestLldbGdbServer.py?rev=207568&r1=207567&r2=207568&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-gdbserver/TestLldbGdbServer.py (original)
+++ lldb/trunk/test/tools/lldb-gdbserver/TestLldbGdbServer.py Tue Apr 29 13:21:07 2014
@@ -21,8 +21,8 @@ class LldbGdbServerTestCase(TestBase):
_GDBREMOTE_KILL_PACKET = "$k#6b"
- _LOGGING_LEVEL = logging.WARNING
- # _LOGGING_LEVEL = logging.DEBUG
+ # _LOGGING_LEVEL = logging.WARNING
+ _LOGGING_LEVEL = logging.DEBUG
def setUp(self):
TestBase.setUp(self)
@@ -177,15 +177,12 @@ class LldbGdbServerTestCase(TestBase):
server = self.start_server()
self.assertIsNotNone(server)
- # TODO grab the build output directory rather than current directory.
- inferior_exe_name = os.path.abspath('a.out')
- inferior_exe_name_hex = gdbremote_hex_encode_string(inferior_exe_name)
+ # build launch args
+ launch_args = [os.path.abspath('a.out')]
log_lines = self.create_no_ack_remote_stream()
log_lines.extend([
- "lldb-gdbserver < 000> read packet: {}".format(
- gdbremote_packet_encode_string(
- "A{},0,{}".format(len(inferior_exe_name_hex), inferior_exe_name_hex))),
+ "lldb-gdbserver < 0> read packet: %s" % build_gdbremote_A_packet(launch_args),
"lldb-gdbserver < 6> send packet: $OK#9a"])
expect_lldb_gdbserver_replay(self, self.sock, log_lines, True,
@@ -205,19 +202,86 @@ class LldbGdbServerTestCase(TestBase):
self.buildDwarf()
self.start_inferior()
+ def inferior_exit_0(self):
+ server = self.start_server()
+ self.assertIsNotNone(server)
+
+ # build launch args
+ launch_args = [os.path.abspath('a.out')]
+
+ log_lines = self.create_no_ack_remote_stream()
+ log_lines.extend([
+ "lldb-gdbserver < 0> read packet: %s" % build_gdbremote_A_packet(launch_args),
+ "lldb-gdbserver < 6> send packet: $OK#00",
+ "lldb-gdbserver < 18> read packet: $qLaunchSuccess#a5",
+ "lldb-gdbserver < 6> send packet: $OK#00",
+ "lldb-gdbserver < 5> read packet: $vCont;c#00",
+ "lldb-gdbserver < 7> send packet: $W00#00"])
+
+ expect_lldb_gdbserver_replay(self, self.sock, log_lines, True,
+ self._TIMEOUT_SECONDS, self.logger)
+
+ @debugserver_test
+ @dsym_test
+ def test_inferior_exit_0_debugserver_dsym(self):
+ self.init_debugserver_test()
+ self.buildDsym()
+ self.inferior_exit_0()
+
+ @llgs_test
+ @dwarf_test
+ @unittest2.expectedFailure()
+ def test_inferior_exit_0_llgs_dwarf(self):
+ self.init_llgs_test()
+ self.buildDwarf()
+ self.inferior_exit_0()
+
+ def inferior_exit_42(self):
+ server = self.start_server()
+ self.assertIsNotNone(server)
+
+ RETVAL = 42
+
+ # build launch args
+ launch_args = [os.path.abspath('a.out'), "retval:%d" % RETVAL]
+
+ log_lines = self.create_no_ack_remote_stream()
+ log_lines.extend([
+ "lldb-gdbserver < 0> read packet: %s" % build_gdbremote_A_packet(launch_args),
+ "lldb-gdbserver < 6> send packet: $OK#00",
+ "lldb-gdbserver < 18> read packet: $qLaunchSuccess#a5",
+ "lldb-gdbserver < 6> send packet: $OK#00",
+ "lldb-gdbserver < 5> read packet: $vCont;c#00",
+ "lldb-gdbserver < 7> send packet: $W{0:02x}#00".format(RETVAL)])
+
+ expect_lldb_gdbserver_replay(self, self.sock, log_lines, True,
+ self._TIMEOUT_SECONDS, self.logger)
+
+ @debugserver_test
+ @dsym_test
+ def test_inferior_exit_42_debugserver_dsym(self):
+ self.init_debugserver_test()
+ self.buildDsym()
+ self.inferior_exit_42()
+
+ @llgs_test
+ @dwarf_test
+ @unittest2.expectedFailure()
+ def test_inferior_exit_42_llgs_dwarf(self):
+ self.init_llgs_test()
+ self.buildDwarf()
+ self.inferior_exit_42()
+
def inferior_print_exit(self):
server = self.start_server()
self.assertIsNotNone(server)
- # TODO grab the build output directory rather than current directory.
- inferior_exe_name = os.path.abspath('a.out')
- inferior_exe_name_hex = gdbremote_hex_encode_string(inferior_exe_name)
+ # build launch args
+ launch_args = [os.path.abspath('a.out'), "hello, world"]
log_lines = self.create_no_ack_remote_stream()
log_lines.extend([
- "lldb-gdbserver < 000> read packet: {}".format(
- gdbremote_packet_encode_string(
- "A{},0,{}".format(len(inferior_exe_name_hex), inferior_exe_name_hex))),
+ "lldb-gdbserver < 0> read packet: %s" % build_gdbremote_A_packet(launch_args),
"lldb-gdbserver < 6> send packet: $OK#00",
"lldb-gdbserver < 18> read packet: $qLaunchSuccess#a5",
"lldb-gdbserver < 6> send packet: $OK#00",
Modified: lldb/trunk/test/tools/lldb-gdbserver/lldbgdbserverutils.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-gdbserver/lldbgdbserverutils.py?rev=207568&r1=207567&r2=207568&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-gdbserver/lldbgdbserverutils.py (original)
+++ lldb/trunk/test/tools/lldb-gdbserver/lldbgdbserverutils.py Tue Apr 29 13:21:07 2014
@@ -241,6 +241,30 @@ def gdbremote_packet_encode_string(str):
return '$' + str + '#{0:02x}'.format(checksum % 256)
+def build_gdbremote_A_packet(args_list):
+ """Given a list of args, create a properly-formed $A packet containing each arg.
+ """
+ payload = "A"
+
+ # build the arg content
+ arg_index = 0
+ for arg in args_list:
+ # Comma-separate the args.
+ if arg_index > 0:
+ payload += ','
+
+ # Hex-encode the arg.
+ hex_arg = gdbremote_hex_encode_string(arg)
+
+ # Build the A entry.
+ payload += "{},{},{}".format(len(hex_arg), arg_index, hex_arg)
+
+ # Next arg index, please.
+ arg_index += 1
+
+ # return the packetized payload
+ return gdbremote_packet_encode_string(payload)
+
if __name__ == '__main__':
EXE_PATH = get_lldb_gdbserver_exe()
if EXE_PATH:
Modified: lldb/trunk/test/tools/lldb-gdbserver/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-gdbserver/main.cpp?rev=207568&r1=207567&r2=207568&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-gdbserver/main.cpp (original)
+++ lldb/trunk/test/tools/lldb-gdbserver/main.cpp Tue Apr 29 13:21:07 2014
@@ -1,7 +1,31 @@
+#include <cstdlib>
+#include <cstring>
#include <iostream>
-int main(int argc, char **argv)
+static const char *const STDERR_PREFIX = "stderr:";
+static const char *const RETVAL_PREFIX = "retval:";
+
+int main (int argc, char **argv)
{
- std::cout << "hello, world" << std::endl;
- return 0;
+ int return_value = 0;
+
+ for (int i = 1; i < argc; ++i)
+ {
+ if (std::strstr (argv[i], STDERR_PREFIX))
+ {
+ // Treat remainder as text to go to stderr.
+ std::cerr << (argv[i] + strlen (STDERR_PREFIX)) << std::endl;
+ }
+ else if (std::strstr (argv[i], RETVAL_PREFIX))
+ {
+ // Treat as the return value for the program.
+ return_value = std::atoi (argv[i] + strlen (RETVAL_PREFIX));
+ }
+ else
+ {
+ // Treat the argument as text for stdout.
+ std::cout << argv[i] << std::endl;
+ }
+ }
+ return return_value;
}
More information about the lldb-commits
mailing list