Changeset View
Standalone View
packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteModuleInfo.py
from __future__ import print_function | from __future__ import print_function | ||||
import json | |||||
import gdbremote_testcase | import gdbremote_testcase | ||||
import lldbgdbserverutils | import lldbgdbserverutils | ||||
from lldbsuite.support import seven | from lldbsuite.support import seven | ||||
from lldbsuite.test.decorators import * | from lldbsuite.test.decorators import * | ||||
from lldbsuite.test.lldbtest import * | from lldbsuite.test.lldbtest import * | ||||
from lldbsuite.test import lldbutil | from lldbsuite.test import lldbutil | ||||
class TestGdbRemoteModuleInfo(gdbremote_testcase.GdbRemoteTestCaseBase): | class TestGdbRemoteModuleInfo(gdbremote_testcase.GdbRemoteTestCaseBase): | ||||
mydir = TestBase.compute_mydir(__file__) | mydir = TestBase.compute_mydir(__file__) | ||||
def module_info(self): | def module_info(self): | ||||
procs = self.prep_debug_monitor_and_inferior() | procs = self.prep_debug_monitor_and_inferior() | ||||
self.add_process_info_collection_packets() | self.add_process_info_collection_packets() | ||||
context = self.expect_gdbremote_sequence() | context = self.expect_gdbremote_sequence() | ||||
info = self.parse_process_info_response(context) | info = self.parse_process_info_response(context) | ||||
self.test_sequence.add_log_lines([ | self.test_sequence.add_log_lines([ | ||||
clayborg: Use json.dumps:
```
module_path = json.dumps(lldbutil.append_to_process_working_directory(self… | |||||
'read packet: $jModulesInfo:[{"file":"%s","triple":"%s"}]]#00' % ( | 'read packet: $jModulesInfo:%s]#00' % json.dumps( | ||||
lldbutil.append_to_process_working_directory(self, "a.out"), | [{"file":lldbutil.append_to_process_working_directory(self, "a.out"), | ||||
seven.unhexlify(info["triple"])), | "triple":seven.unhexlify(info["triple"])}]), | ||||
{"direction": "send", | {"direction": "send", | ||||
"regex": r'^\$\[{(.*)}\]\]#[0-9A-Fa-f]{2}', | "regex": r'^\$\[{(.*)}\]\]#[0-9A-Fa-f]{2}', | ||||
It sounds like you could just unconditionally replace all backslashes with double-backslashes here. That would result in us also correctly handling posix paths that happen to contain a backslash. labath: It sounds like you could just unconditionally replace all backslashes with double-backslashes… | |||||
Remove clayborg: Remove | |||||
The 'jModulesInfo' packet is a json string. I tested with json.loads as follows. not-working case: >>> module_path = 'd:\abc' >>> json.dumps(module_path) '"d:\\u0007bc"' >>> json.loads('[{"[file":"%s"}]' % json.dumps(module_path)) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/json/__init__.py", line 339, in loads return _default_decoder.decode(s) File "/usr/lib/python2.7/json/decoder.py", line 364, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.7/json/decoder.py", line 380, in raw_decode obj, end = self.scan_once(s, idx) ValueError: Expecting , delimiter: line 1 column 13 (char 12) working case: >>> module_path = 'd:\\\\abc' >>> json.loads('[{"[file":"%s"}]' % module_path) [{u'[file': u'd:\\abc'}] Hui: The 'jModulesInfo' packet is a json string. I tested with json.loads as follows.
It seemed to… | |||||
There are multiple levels of quoting happening here, and I believe you're getting them mixed up:
This is already wrong, because python will interpret the \a as the ASCII BEL character, resulting in the string consisting of: 'd', ':', BEL, 'b', 'c' >>> "d:\abc" 'd:\x07bc' The easiest fix is to use "raw" python strings: r"d:\abc" 'd:\\abc' Note that the '\' in the output string it's not doubled, it is just how the python dumper makes sure the output is unambiguous. You can for instance check that with: len(r"d:\abc") which returns 6 as expected. After that, your not-working case works almost fine: >>> json.loads('[{"[file":"%s"}]' % json.dumps(module_path)) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python3.6/json/__init__.py", line 354, in loads return _default_decoder.decode(s) File "/usr/lib64/python3.6/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib64/python3.6/json/decoder.py", line 355, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 13 (char 12) >>> json.loads('[{"[file":%s}]' % json.dumps(module_path)) [{'[file': 'd:\\abc'}] Note I removed the superfluous quotes in the second attempt. However, if we're going to be using the json package for this, then there's an even simpler way to write this: >>> json.dumps([{"file": module_path}]) '[{"file": "d:\\\\abc"}]' >>> json.loads(json.dumps([{"file": module_path}])) [{'file': 'd:\\abc'}] labath: There are multiple levels of quoting happening here, and I believe you're getting them mixed up… | |||||
"capture": {1: "spec"}}, | "capture": {1: "spec"}}, | ||||
], True) | ], True) | ||||
context = self.expect_gdbremote_sequence() | context = self.expect_gdbremote_sequence() | ||||
spec = context.get("spec") | spec = context.get("spec") | ||||
self.assertRegexpMatches(spec, '"file_path":".*"') | self.assertRegexpMatches(spec, '"file_path":".*"') | ||||
self.assertRegexpMatches(spec, '"file_offset":\d+') | self.assertRegexpMatches(spec, '"file_offset":\d+') | ||||
self.assertRegexpMatches(spec, '"file_size":\d+') | self.assertRegexpMatches(spec, '"file_size":\d+') | ||||
Show All 9 Lines |
Use json.dumps: