2010-09-09 06:54:46 +08:00
|
|
|
"""
|
2010-10-08 05:38:28 +08:00
|
|
|
This LLDB module contains miscellaneous utilities.
|
2011-05-14 05:55:30 +08:00
|
|
|
Some of the test suite takes advantage of the utility functions defined here.
|
|
|
|
They can also be useful for general purpose lldb scripting.
|
2010-09-09 06:54:46 +08:00
|
|
|
"""
|
|
|
|
|
2015-10-20 07:45:41 +08:00
|
|
|
from __future__ import print_function
|
Python 3 - Turn on absolute imports, and fix existing imports.
Absolute imports were introduced in Python 2.5 as a feature
(e.g. from __future__ import absolute_import), and made default
in Python 3.
When absolute imports are enabled, the import system changes in
a couple of ways:
1) The `import foo` syntax will *only* search sys.path. If `foo`
isn't in sys.path, it won't be found. Period. Without absolute
imports, the import system will also search the same directory
that the importing file resides in, so that you can easily
import from the same folder.
2) From inside a package, you can use a dot syntax to refer to higher
levels of the current package. For example, if you are in the
package lldbsuite.test.utility, then ..foo refers to
lldbsuite.test.foo. You can use this notation with the
`from X import Y` syntax to write intra-package references. For
example, using the previous locationa s a starting point, writing
`from ..support import seven` would import lldbsuite.support.seven
Since this is now the default behavior in Python 3, this means that
importing from the same directory with `import foo` *no longer works*.
As a result, the only way to have portable code is to force absolute
imports for all versions of Python.
See PEP 0328 [https://www.python.org/dev/peps/pep-0328/] for more
information about absolute and relative imports.
Differential Revision: http://reviews.llvm.org/D14342
Reviewed By: Todd Fiala
llvm-svn: 252191
2015-11-06 03:22:28 +08:00
|
|
|
from __future__ import absolute_import
|
2015-10-20 07:45:41 +08:00
|
|
|
|
Python 3 - Turn on absolute imports, and fix existing imports.
Absolute imports were introduced in Python 2.5 as a feature
(e.g. from __future__ import absolute_import), and made default
in Python 3.
When absolute imports are enabled, the import system changes in
a couple of ways:
1) The `import foo` syntax will *only* search sys.path. If `foo`
isn't in sys.path, it won't be found. Period. Without absolute
imports, the import system will also search the same directory
that the importing file resides in, so that you can easily
import from the same folder.
2) From inside a package, you can use a dot syntax to refer to higher
levels of the current package. For example, if you are in the
package lldbsuite.test.utility, then ..foo refers to
lldbsuite.test.foo. You can use this notation with the
`from X import Y` syntax to write intra-package references. For
example, using the previous locationa s a starting point, writing
`from ..support import seven` would import lldbsuite.support.seven
Since this is now the default behavior in Python 3, this means that
importing from the same directory with `import foo` *no longer works*.
As a result, the only way to have portable code is to force absolute
imports for all versions of Python.
See PEP 0328 [https://www.python.org/dev/peps/pep-0328/] for more
information about absolute and relative imports.
Differential Revision: http://reviews.llvm.org/D14342
Reviewed By: Todd Fiala
llvm-svn: 252191
2015-11-06 03:22:28 +08:00
|
|
|
# System modules
|
2018-01-31 02:29:16 +08:00
|
|
|
import errno
|
Python 3 - Turn on absolute imports, and fix existing imports.
Absolute imports were introduced in Python 2.5 as a feature
(e.g. from __future__ import absolute_import), and made default
in Python 3.
When absolute imports are enabled, the import system changes in
a couple of ways:
1) The `import foo` syntax will *only* search sys.path. If `foo`
isn't in sys.path, it won't be found. Period. Without absolute
imports, the import system will also search the same directory
that the importing file resides in, so that you can easily
import from the same folder.
2) From inside a package, you can use a dot syntax to refer to higher
levels of the current package. For example, if you are in the
package lldbsuite.test.utility, then ..foo refers to
lldbsuite.test.foo. You can use this notation with the
`from X import Y` syntax to write intra-package references. For
example, using the previous locationa s a starting point, writing
`from ..support import seven` would import lldbsuite.support.seven
Since this is now the default behavior in Python 3, this means that
importing from the same directory with `import foo` *no longer works*.
As a result, the only way to have portable code is to force absolute
imports for all versions of Python.
See PEP 0328 [https://www.python.org/dev/peps/pep-0328/] for more
information about absolute and relative imports.
Differential Revision: http://reviews.llvm.org/D14342
Reviewed By: Todd Fiala
llvm-svn: 252191
2015-11-06 03:22:28 +08:00
|
|
|
import os
|
2015-09-19 04:12:52 +08:00
|
|
|
import re
|
Python 3 - Turn on absolute imports, and fix existing imports.
Absolute imports were introduced in Python 2.5 as a feature
(e.g. from __future__ import absolute_import), and made default
in Python 3.
When absolute imports are enabled, the import system changes in
a couple of ways:
1) The `import foo` syntax will *only* search sys.path. If `foo`
isn't in sys.path, it won't be found. Period. Without absolute
imports, the import system will also search the same directory
that the importing file resides in, so that you can easily
import from the same folder.
2) From inside a package, you can use a dot syntax to refer to higher
levels of the current package. For example, if you are in the
package lldbsuite.test.utility, then ..foo refers to
lldbsuite.test.foo. You can use this notation with the
`from X import Y` syntax to write intra-package references. For
example, using the previous locationa s a starting point, writing
`from ..support import seven` would import lldbsuite.support.seven
Since this is now the default behavior in Python 3, this means that
importing from the same directory with `import foo` *no longer works*.
As a result, the only way to have portable code is to force absolute
imports for all versions of Python.
See PEP 0328 [https://www.python.org/dev/peps/pep-0328/] for more
information about absolute and relative imports.
Differential Revision: http://reviews.llvm.org/D14342
Reviewed By: Todd Fiala
llvm-svn: 252191
2015-11-06 03:22:28 +08:00
|
|
|
import sys
|
2020-08-20 04:25:57 +08:00
|
|
|
import subprocess
|
2010-09-09 06:54:46 +08:00
|
|
|
|
Python 3 - Turn on absolute imports, and fix existing imports.
Absolute imports were introduced in Python 2.5 as a feature
(e.g. from __future__ import absolute_import), and made default
in Python 3.
When absolute imports are enabled, the import system changes in
a couple of ways:
1) The `import foo` syntax will *only* search sys.path. If `foo`
isn't in sys.path, it won't be found. Period. Without absolute
imports, the import system will also search the same directory
that the importing file resides in, so that you can easily
import from the same folder.
2) From inside a package, you can use a dot syntax to refer to higher
levels of the current package. For example, if you are in the
package lldbsuite.test.utility, then ..foo refers to
lldbsuite.test.foo. You can use this notation with the
`from X import Y` syntax to write intra-package references. For
example, using the previous locationa s a starting point, writing
`from ..support import seven` would import lldbsuite.support.seven
Since this is now the default behavior in Python 3, this means that
importing from the same directory with `import foo` *no longer works*.
As a result, the only way to have portable code is to force absolute
imports for all versions of Python.
See PEP 0328 [https://www.python.org/dev/peps/pep-0328/] for more
information about absolute and relative imports.
Differential Revision: http://reviews.llvm.org/D14342
Reviewed By: Todd Fiala
llvm-svn: 252191
2015-11-06 03:22:28 +08:00
|
|
|
# Third-party modules
|
2015-10-22 01:48:52 +08:00
|
|
|
from six import StringIO as SixStringIO
|
2015-10-27 02:48:24 +08:00
|
|
|
import six
|
Python 3 - Turn on absolute imports, and fix existing imports.
Absolute imports were introduced in Python 2.5 as a feature
(e.g. from __future__ import absolute_import), and made default
in Python 3.
When absolute imports are enabled, the import system changes in
a couple of ways:
1) The `import foo` syntax will *only* search sys.path. If `foo`
isn't in sys.path, it won't be found. Period. Without absolute
imports, the import system will also search the same directory
that the importing file resides in, so that you can easily
import from the same folder.
2) From inside a package, you can use a dot syntax to refer to higher
levels of the current package. For example, if you are in the
package lldbsuite.test.utility, then ..foo refers to
lldbsuite.test.foo. You can use this notation with the
`from X import Y` syntax to write intra-package references. For
example, using the previous locationa s a starting point, writing
`from ..support import seven` would import lldbsuite.support.seven
Since this is now the default behavior in Python 3, this means that
importing from the same directory with `import foo` *no longer works*.
As a result, the only way to have portable code is to force absolute
imports for all versions of Python.
See PEP 0328 [https://www.python.org/dev/peps/pep-0328/] for more
information about absolute and relative imports.
Differential Revision: http://reviews.llvm.org/D14342
Reviewed By: Todd Fiala
llvm-svn: 252191
2015-11-06 03:22:28 +08:00
|
|
|
|
|
|
|
# LLDB modules
|
|
|
|
import lldb
|
2019-12-12 08:19:08 +08:00
|
|
|
from . import lldbtest_config
|
2021-04-02 01:00:52 +08:00
|
|
|
from . import configuration
|
Python 3 - Turn on absolute imports, and fix existing imports.
Absolute imports were introduced in Python 2.5 as a feature
(e.g. from __future__ import absolute_import), and made default
in Python 3.
When absolute imports are enabled, the import system changes in
a couple of ways:
1) The `import foo` syntax will *only* search sys.path. If `foo`
isn't in sys.path, it won't be found. Period. Without absolute
imports, the import system will also search the same directory
that the importing file resides in, so that you can easily
import from the same folder.
2) From inside a package, you can use a dot syntax to refer to higher
levels of the current package. For example, if you are in the
package lldbsuite.test.utility, then ..foo refers to
lldbsuite.test.foo. You can use this notation with the
`from X import Y` syntax to write intra-package references. For
example, using the previous locationa s a starting point, writing
`from ..support import seven` would import lldbsuite.support.seven
Since this is now the default behavior in Python 3, this means that
importing from the same directory with `import foo` *no longer works*.
As a result, the only way to have portable code is to force absolute
imports for all versions of Python.
See PEP 0328 [https://www.python.org/dev/peps/pep-0328/] for more
information about absolute and relative imports.
Differential Revision: http://reviews.llvm.org/D14342
Reviewed By: Todd Fiala
llvm-svn: 252191
2015-11-06 03:22:28 +08:00
|
|
|
|
2020-08-08 04:28:05 +08:00
|
|
|
# How often failed simulator process launches are retried.
|
|
|
|
SIMULATOR_RETRY = 3
|
2015-10-22 01:48:52 +08:00
|
|
|
|
2011-04-27 07:07:40 +08:00
|
|
|
# ===================================================
|
|
|
|
# Utilities for locating/checking executable programs
|
|
|
|
# ===================================================
|
2011-04-27 06:53:38 +08:00
|
|
|
|
Turns out that the test failure wrt:
rdar://problem/9173060 lldb hangs while running unique-types
disappears if running with clang version >= 3. Modify the TestUniqueTypes.py
to detect if we are running with clang version < 3 and, if true, skip the test.
Update the lldbtest.system() function to return a tuple of (stdoutdata, stderrdata)
since we need the stderr data from "clang -v" command. Modify existing clients of
lldbtest.system() to now use, for example:
# First, capture the golden output emitted by the oracle, i.e., the
# series of printf statements.
- go = system("./a.out", sender=self)
+ go = system("./a.out", sender=self)[0]
# This golden list contains a list of (variable, value) pairs extracted
# from the golden output.
gl = []
And add two utility functions to lldbutil.py.
llvm-svn: 128162
2011-03-24 04:28:59 +08:00
|
|
|
def is_exe(fpath):
|
2011-04-27 07:10:15 +08:00
|
|
|
"""Returns True if fpath is an executable."""
|
Turns out that the test failure wrt:
rdar://problem/9173060 lldb hangs while running unique-types
disappears if running with clang version >= 3. Modify the TestUniqueTypes.py
to detect if we are running with clang version < 3 and, if true, skip the test.
Update the lldbtest.system() function to return a tuple of (stdoutdata, stderrdata)
since we need the stderr data from "clang -v" command. Modify existing clients of
lldbtest.system() to now use, for example:
# First, capture the golden output emitted by the oracle, i.e., the
# series of printf statements.
- go = system("./a.out", sender=self)
+ go = system("./a.out", sender=self)[0]
# This golden list contains a list of (variable, value) pairs extracted
# from the golden output.
gl = []
And add two utility functions to lldbutil.py.
llvm-svn: 128162
2011-03-24 04:28:59 +08:00
|
|
|
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
Turns out that the test failure wrt:
rdar://problem/9173060 lldb hangs while running unique-types
disappears if running with clang version >= 3. Modify the TestUniqueTypes.py
to detect if we are running with clang version < 3 and, if true, skip the test.
Update the lldbtest.system() function to return a tuple of (stdoutdata, stderrdata)
since we need the stderr data from "clang -v" command. Modify existing clients of
lldbtest.system() to now use, for example:
# First, capture the golden output emitted by the oracle, i.e., the
# series of printf statements.
- go = system("./a.out", sender=self)
+ go = system("./a.out", sender=self)[0]
# This golden list contains a list of (variable, value) pairs extracted
# from the golden output.
gl = []
And add two utility functions to lldbutil.py.
llvm-svn: 128162
2011-03-24 04:28:59 +08:00
|
|
|
def which(program):
|
2011-04-27 07:10:15 +08:00
|
|
|
"""Returns the full path to a program; None otherwise."""
|
Turns out that the test failure wrt:
rdar://problem/9173060 lldb hangs while running unique-types
disappears if running with clang version >= 3. Modify the TestUniqueTypes.py
to detect if we are running with clang version < 3 and, if true, skip the test.
Update the lldbtest.system() function to return a tuple of (stdoutdata, stderrdata)
since we need the stderr data from "clang -v" command. Modify existing clients of
lldbtest.system() to now use, for example:
# First, capture the golden output emitted by the oracle, i.e., the
# series of printf statements.
- go = system("./a.out", sender=self)
+ go = system("./a.out", sender=self)[0]
# This golden list contains a list of (variable, value) pairs extracted
# from the golden output.
gl = []
And add two utility functions to lldbutil.py.
llvm-svn: 128162
2011-03-24 04:28:59 +08:00
|
|
|
fpath, fname = os.path.split(program)
|
|
|
|
if fpath:
|
|
|
|
if is_exe(program):
|
|
|
|
return program
|
|
|
|
else:
|
|
|
|
for path in os.environ["PATH"].split(os.pathsep):
|
|
|
|
exe_file = os.path.join(path, program)
|
|
|
|
if is_exe(exe_file):
|
|
|
|
return exe_file
|
|
|
|
return None
|
|
|
|
|
2018-01-31 02:29:16 +08:00
|
|
|
def mkdir_p(path):
|
|
|
|
try:
|
|
|
|
os.makedirs(path)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.EEXIST:
|
|
|
|
raise
|
|
|
|
if not os.path.isdir(path):
|
|
|
|
raise OSError(errno.ENOTDIR, "%s is not a directory"%path)
|
2020-08-20 04:25:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
# ============================
|
|
|
|
# Dealing with SDK and triples
|
|
|
|
# ============================
|
|
|
|
|
|
|
|
def get_xcode_sdk(os, env):
|
2021-04-02 01:00:52 +08:00
|
|
|
# Respect --apple-sdk <path> if it's specified. If the SDK is simply
|
|
|
|
# mounted from some disk image, and not actually installed, this is the
|
|
|
|
# only way to use it.
|
|
|
|
if configuration.apple_sdk:
|
|
|
|
return configuration.apple_sdk
|
2020-08-20 04:25:57 +08:00
|
|
|
if os == "ios":
|
|
|
|
if env == "simulator":
|
|
|
|
return "iphonesimulator"
|
|
|
|
if env == "macabi":
|
|
|
|
return "macosx"
|
|
|
|
return "iphoneos"
|
|
|
|
elif os == "tvos":
|
|
|
|
if env == "simulator":
|
|
|
|
return "appletvsimulator"
|
|
|
|
return "appletvos"
|
|
|
|
elif os == "watchos":
|
|
|
|
if env == "simulator":
|
|
|
|
return "watchsimulator"
|
|
|
|
return "watchos"
|
|
|
|
return os
|
|
|
|
|
|
|
|
|
|
|
|
def get_xcode_sdk_version(sdk):
|
|
|
|
return subprocess.check_output(
|
|
|
|
['xcrun', '--sdk', sdk, '--show-sdk-version']).rstrip().decode('utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
def get_xcode_sdk_root(sdk):
|
|
|
|
return subprocess.check_output(['xcrun', '--sdk', sdk, '--show-sdk-path'
|
|
|
|
]).rstrip().decode('utf-8')
|
|
|
|
|
|
|
|
|
2021-04-22 04:18:36 +08:00
|
|
|
def get_xcode_clang(sdk):
|
|
|
|
return subprocess.check_output(['xcrun', '-sdk', sdk, '-f', 'clang'
|
|
|
|
]).rstrip().decode("utf-8")
|
|
|
|
|
|
|
|
|
2011-03-04 03:14:00 +08:00
|
|
|
# ===================================================
|
|
|
|
# Disassembly for an SBFunction or an SBSymbol object
|
|
|
|
# ===================================================
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-03-04 03:14:00 +08:00
|
|
|
def disassemble(target, function_or_symbol):
|
|
|
|
"""Disassemble the function or symbol given a target.
|
|
|
|
|
|
|
|
It returns the disassembly content in a string object.
|
|
|
|
"""
|
2015-10-22 01:48:52 +08:00
|
|
|
buf = SixStringIO()
|
2011-03-04 03:14:00 +08:00
|
|
|
insts = function_or_symbol.GetInstructions(target)
|
2011-04-29 06:57:01 +08:00
|
|
|
for i in insts:
|
2015-10-20 07:45:41 +08:00
|
|
|
print(i, file=buf)
|
2011-03-04 03:14:00 +08:00
|
|
|
return buf.getvalue()
|
|
|
|
|
2011-03-02 09:36:45 +08:00
|
|
|
# ==========================================================
|
|
|
|
# Integer (byte size 1, 2, 4, and 8) to bytearray conversion
|
|
|
|
# ==========================================================
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-03-02 09:36:45 +08:00
|
|
|
def int_to_bytearray(val, bytesize):
|
|
|
|
"""Utility function to convert an integer into a bytearray.
|
|
|
|
|
2011-03-03 04:54:22 +08:00
|
|
|
It returns the bytearray in the little endian format. It is easy to get the
|
|
|
|
big endian format, just do ba.reverse() on the returned object.
|
2011-03-02 09:36:45 +08:00
|
|
|
"""
|
2011-03-31 01:54:35 +08:00
|
|
|
import struct
|
2011-03-02 09:36:45 +08:00
|
|
|
|
|
|
|
if bytesize == 1:
|
|
|
|
return bytearray([val])
|
|
|
|
|
|
|
|
# Little endian followed by a format character.
|
|
|
|
template = "<%c"
|
|
|
|
if bytesize == 2:
|
|
|
|
fmt = template % 'h'
|
|
|
|
elif bytesize == 4:
|
|
|
|
fmt = template % 'i'
|
|
|
|
elif bytesize == 4:
|
|
|
|
fmt = template % 'q'
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2011-03-31 01:54:35 +08:00
|
|
|
packed = struct.pack(fmt, val)
|
2016-01-26 07:21:18 +08:00
|
|
|
return bytearray(packed)
|
2011-03-02 09:36:45 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-03-02 09:36:45 +08:00
|
|
|
def bytearray_to_int(bytes, bytesize):
|
|
|
|
"""Utility function to convert a bytearray into an integer.
|
|
|
|
|
2011-03-03 04:54:22 +08:00
|
|
|
It interprets the bytearray in the little endian format. For a big endian
|
|
|
|
bytearray, just do ba.reverse() on the object before passing it in.
|
2011-03-02 09:36:45 +08:00
|
|
|
"""
|
2011-03-31 01:54:35 +08:00
|
|
|
import struct
|
2011-03-02 09:36:45 +08:00
|
|
|
|
|
|
|
if bytesize == 1:
|
2012-07-07 00:20:13 +08:00
|
|
|
return bytes[0]
|
2011-03-02 09:36:45 +08:00
|
|
|
|
|
|
|
# Little endian followed by a format character.
|
|
|
|
template = "<%c"
|
|
|
|
if bytesize == 2:
|
|
|
|
fmt = template % 'h'
|
|
|
|
elif bytesize == 4:
|
|
|
|
fmt = template % 'i'
|
|
|
|
elif bytesize == 4:
|
|
|
|
fmt = template % 'q'
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2016-01-26 07:21:18 +08:00
|
|
|
unpacked = struct.unpack_from(fmt, bytes)
|
2011-03-02 09:36:45 +08:00
|
|
|
return unpacked[0]
|
|
|
|
|
|
|
|
|
2011-04-23 08:13:34 +08:00
|
|
|
# ==============================================================
|
|
|
|
# Get the description of an lldb object or None if not available
|
|
|
|
# ==============================================================
|
2011-04-26 04:23:05 +08:00
|
|
|
def get_description(obj, option=None):
|
|
|
|
"""Calls lldb_obj.GetDescription() and returns a string, or None.
|
|
|
|
|
2011-10-14 08:42:25 +08:00
|
|
|
For SBTarget, SBBreakpointLocation, and SBWatchpoint lldb objects, an extra
|
|
|
|
option can be passed in to describe the detailed level of description
|
|
|
|
desired:
|
2011-04-26 04:23:05 +08:00
|
|
|
o lldb.eDescriptionLevelBrief
|
|
|
|
o lldb.eDescriptionLevelFull
|
|
|
|
o lldb.eDescriptionLevelVerbose
|
|
|
|
"""
|
|
|
|
method = getattr(obj, 'GetDescription')
|
2011-04-23 08:13:34 +08:00
|
|
|
if not method:
|
|
|
|
return None
|
2011-10-14 08:42:25 +08:00
|
|
|
tuple = (lldb.SBTarget, lldb.SBBreakpointLocation, lldb.SBWatchpoint)
|
2011-09-28 05:27:19 +08:00
|
|
|
if isinstance(obj, tuple):
|
2011-04-26 04:23:05 +08:00
|
|
|
if option is None:
|
|
|
|
option = lldb.eDescriptionLevelBrief
|
|
|
|
|
2011-04-23 08:13:34 +08:00
|
|
|
stream = lldb.SBStream()
|
|
|
|
if option is None:
|
|
|
|
success = method(stream)
|
|
|
|
else:
|
|
|
|
success = method(stream, option)
|
|
|
|
if not success:
|
|
|
|
return None
|
|
|
|
return stream.GetData()
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-23 08:13:34 +08:00
|
|
|
|
2010-10-23 05:31:03 +08:00
|
|
|
# =================================================
|
|
|
|
# Convert some enum value to its string counterpart
|
|
|
|
# =================================================
|
2010-10-08 06:15:58 +08:00
|
|
|
|
2011-04-28 01:43:07 +08:00
|
|
|
def state_type_to_str(enum):
|
2010-10-08 06:15:58 +08:00
|
|
|
"""Returns the stateType string given an enum."""
|
|
|
|
if enum == lldb.eStateInvalid:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "invalid"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateUnloaded:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "unloaded"
|
2011-03-05 09:20:11 +08:00
|
|
|
elif enum == lldb.eStateConnected:
|
|
|
|
return "connected"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateAttaching:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "attaching"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateLaunching:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "launching"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateStopped:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "stopped"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateRunning:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "running"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateStepping:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "stepping"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateCrashed:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "crashed"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateDetached:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "detached"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateExited:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "exited"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateSuspended:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "suspended"
|
2010-10-08 06:15:58 +08:00
|
|
|
else:
|
2011-03-05 09:20:11 +08:00
|
|
|
raise Exception("Unknown StateType enum")
|
2010-10-08 06:15:58 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-28 01:43:07 +08:00
|
|
|
def stop_reason_to_str(enum):
|
2010-10-08 06:15:58 +08:00
|
|
|
"""Returns the stopReason string given an enum."""
|
|
|
|
if enum == lldb.eStopReasonInvalid:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "invalid"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStopReasonNone:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "none"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStopReasonTrace:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "trace"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStopReasonBreakpoint:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "breakpoint"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStopReasonWatchpoint:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "watchpoint"
|
2014-04-03 09:25:28 +08:00
|
|
|
elif enum == lldb.eStopReasonExec:
|
|
|
|
return "exec"
|
2021-03-29 23:05:30 +08:00
|
|
|
elif enum == lldb.eStopReasonFork:
|
|
|
|
return "fork"
|
|
|
|
elif enum == lldb.eStopReasonVFork:
|
|
|
|
return "vfork"
|
|
|
|
elif enum == lldb.eStopReasonVForkDone:
|
|
|
|
return "vforkdone"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStopReasonSignal:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "signal"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStopReasonException:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "exception"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStopReasonPlanComplete:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "plancomplete"
|
2013-07-09 08:08:01 +08:00
|
|
|
elif enum == lldb.eStopReasonThreadExiting:
|
|
|
|
return "threadexiting"
|
2010-10-08 06:15:58 +08:00
|
|
|
else:
|
2011-03-05 09:20:11 +08:00
|
|
|
raise Exception("Unknown StopReason enum")
|
2010-10-08 06:15:58 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-09-28 08:51:00 +08:00
|
|
|
def symbol_type_to_str(enum):
|
|
|
|
"""Returns the symbolType string given an enum."""
|
|
|
|
if enum == lldb.eSymbolTypeInvalid:
|
|
|
|
return "invalid"
|
|
|
|
elif enum == lldb.eSymbolTypeAbsolute:
|
|
|
|
return "absolute"
|
|
|
|
elif enum == lldb.eSymbolTypeCode:
|
|
|
|
return "code"
|
|
|
|
elif enum == lldb.eSymbolTypeData:
|
|
|
|
return "data"
|
|
|
|
elif enum == lldb.eSymbolTypeTrampoline:
|
|
|
|
return "trampoline"
|
|
|
|
elif enum == lldb.eSymbolTypeRuntime:
|
|
|
|
return "runtime"
|
|
|
|
elif enum == lldb.eSymbolTypeException:
|
|
|
|
return "exception"
|
|
|
|
elif enum == lldb.eSymbolTypeSourceFile:
|
|
|
|
return "sourcefile"
|
|
|
|
elif enum == lldb.eSymbolTypeHeaderFile:
|
|
|
|
return "headerfile"
|
|
|
|
elif enum == lldb.eSymbolTypeObjectFile:
|
|
|
|
return "objectfile"
|
|
|
|
elif enum == lldb.eSymbolTypeCommonBlock:
|
|
|
|
return "commonblock"
|
|
|
|
elif enum == lldb.eSymbolTypeBlock:
|
|
|
|
return "block"
|
|
|
|
elif enum == lldb.eSymbolTypeLocal:
|
|
|
|
return "local"
|
|
|
|
elif enum == lldb.eSymbolTypeParam:
|
|
|
|
return "param"
|
|
|
|
elif enum == lldb.eSymbolTypeVariable:
|
|
|
|
return "variable"
|
|
|
|
elif enum == lldb.eSymbolTypeVariableType:
|
|
|
|
return "variabletype"
|
|
|
|
elif enum == lldb.eSymbolTypeLineEntry:
|
|
|
|
return "lineentry"
|
|
|
|
elif enum == lldb.eSymbolTypeLineHeader:
|
|
|
|
return "lineheader"
|
|
|
|
elif enum == lldb.eSymbolTypeScopeBegin:
|
|
|
|
return "scopebegin"
|
|
|
|
elif enum == lldb.eSymbolTypeScopeEnd:
|
|
|
|
return "scopeend"
|
|
|
|
elif enum == lldb.eSymbolTypeAdditional:
|
|
|
|
return "additional"
|
|
|
|
elif enum == lldb.eSymbolTypeCompiler:
|
|
|
|
return "compiler"
|
|
|
|
elif enum == lldb.eSymbolTypeInstrumentation:
|
|
|
|
return "instrumentation"
|
|
|
|
elif enum == lldb.eSymbolTypeUndefined:
|
|
|
|
return "undefined"
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-28 01:43:07 +08:00
|
|
|
def value_type_to_str(enum):
|
2010-11-04 05:37:58 +08:00
|
|
|
"""Returns the valueType string given an enum."""
|
|
|
|
if enum == lldb.eValueTypeInvalid:
|
|
|
|
return "invalid"
|
|
|
|
elif enum == lldb.eValueTypeVariableGlobal:
|
|
|
|
return "global_variable"
|
|
|
|
elif enum == lldb.eValueTypeVariableStatic:
|
|
|
|
return "static_variable"
|
|
|
|
elif enum == lldb.eValueTypeVariableArgument:
|
|
|
|
return "argument_variable"
|
|
|
|
elif enum == lldb.eValueTypeVariableLocal:
|
|
|
|
return "local_variable"
|
|
|
|
elif enum == lldb.eValueTypeRegister:
|
|
|
|
return "register"
|
|
|
|
elif enum == lldb.eValueTypeRegisterSet:
|
|
|
|
return "register_set"
|
|
|
|
elif enum == lldb.eValueTypeConstResult:
|
|
|
|
return "constant_result"
|
|
|
|
else:
|
2011-03-05 09:20:11 +08:00
|
|
|
raise Exception("Unknown ValueType enum")
|
2010-11-04 05:37:58 +08:00
|
|
|
|
2010-10-08 06:15:58 +08:00
|
|
|
|
2013-07-09 08:08:01 +08:00
|
|
|
# ==================================================
|
|
|
|
# Get stopped threads due to each stop reason.
|
|
|
|
# ==================================================
|
|
|
|
|
|
|
|
def sort_stopped_threads(process,
|
|
|
|
breakpoint_threads=None,
|
|
|
|
crashed_threads=None,
|
|
|
|
watchpoint_threads=None,
|
|
|
|
signal_threads=None,
|
|
|
|
exiting_threads=None,
|
|
|
|
other_threads=None):
|
|
|
|
""" Fills array *_threads with threads stopped for the corresponding stop
|
|
|
|
reason.
|
|
|
|
"""
|
|
|
|
for lst in [breakpoint_threads,
|
|
|
|
watchpoint_threads,
|
|
|
|
signal_threads,
|
|
|
|
exiting_threads,
|
|
|
|
other_threads]:
|
|
|
|
if lst is not None:
|
|
|
|
lst[:] = []
|
|
|
|
|
|
|
|
for thread in process:
|
|
|
|
dispatched = False
|
|
|
|
for (reason, list) in [(lldb.eStopReasonBreakpoint, breakpoint_threads),
|
|
|
|
(lldb.eStopReasonException, crashed_threads),
|
|
|
|
(lldb.eStopReasonWatchpoint, watchpoint_threads),
|
|
|
|
(lldb.eStopReasonSignal, signal_threads),
|
|
|
|
(lldb.eStopReasonThreadExiting, exiting_threads),
|
|
|
|
(None, other_threads)]:
|
|
|
|
if not dispatched and list is not None:
|
|
|
|
if thread.GetStopReason() == reason or reason is None:
|
|
|
|
list.append(thread)
|
|
|
|
dispatched = True
|
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
# ==================================================
|
|
|
|
# Utility functions for setting breakpoints
|
|
|
|
# ==================================================
|
|
|
|
|
2018-09-14 05:35:32 +08:00
|
|
|
def run_break_set_by_script(
|
|
|
|
test,
|
|
|
|
class_name,
|
|
|
|
extra_options=None,
|
|
|
|
num_expected_locations=1):
|
|
|
|
"""Set a scripted breakpoint. Check that it got the right number of locations."""
|
|
|
|
test.assertTrue(class_name is not None, "Must pass in a class name.")
|
|
|
|
command = "breakpoint set -P " + class_name
|
|
|
|
if extra_options is not None:
|
|
|
|
command += " " + extra_options
|
|
|
|
|
|
|
|
break_results = run_break_set_command(test, command)
|
|
|
|
check_breakpoint_result(test, break_results, num_locations=num_expected_locations)
|
|
|
|
return get_bpno_from_match(break_results)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
def run_break_set_by_file_and_line(
|
|
|
|
test,
|
|
|
|
file_name,
|
|
|
|
line_number,
|
|
|
|
extra_options=None,
|
|
|
|
num_expected_locations=1,
|
|
|
|
loc_exact=False,
|
|
|
|
module_name=None):
|
|
|
|
"""Set a breakpoint by file and line, returning the breakpoint number.
|
|
|
|
|
|
|
|
If extra_options is not None, then we append it to the breakpoint set command.
|
|
|
|
|
2018-02-22 02:08:23 +08:00
|
|
|
If num_expected_locations is -1, we check that we got AT LEAST one location. If num_expected_locations is -2, we don't
|
|
|
|
check the actual number at all. Otherwise, we check that num_expected_locations equals the number of locations.
|
2012-09-22 08:05:11 +08:00
|
|
|
|
|
|
|
If loc_exact is true, we check that there is one location, and that location must be at the input file and line number."""
|
|
|
|
|
|
|
|
if file_name is None:
|
|
|
|
command = 'breakpoint set -l %d' % (line_number)
|
|
|
|
else:
|
|
|
|
command = 'breakpoint set -f "%s" -l %d' % (file_name, line_number)
|
|
|
|
|
2013-01-08 08:01:36 +08:00
|
|
|
if module_name:
|
|
|
|
command += " --shlib '%s'" % (module_name)
|
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
if extra_options:
|
|
|
|
command += " " + extra_options
|
|
|
|
|
|
|
|
break_results = run_break_set_command(test, command)
|
|
|
|
|
|
|
|
if num_expected_locations == 1 and loc_exact:
|
|
|
|
check_breakpoint_result(
|
|
|
|
test,
|
|
|
|
break_results,
|
|
|
|
num_locations=num_expected_locations,
|
|
|
|
file_name=file_name,
|
|
|
|
line_number=line_number,
|
|
|
|
module_name=module_name)
|
|
|
|
else:
|
|
|
|
check_breakpoint_result(
|
|
|
|
test,
|
|
|
|
break_results,
|
|
|
|
num_locations=num_expected_locations)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
return get_bpno_from_match(break_results)
|
|
|
|
|
|
|
|
|
|
|
|
def run_break_set_by_symbol(
|
|
|
|
test,
|
|
|
|
symbol,
|
|
|
|
extra_options=None,
|
|
|
|
num_expected_locations=-1,
|
|
|
|
sym_exact=False,
|
|
|
|
module_name=None):
|
|
|
|
"""Set a breakpoint by symbol name. Common options are the same as run_break_set_by_file_and_line.
|
|
|
|
|
|
|
|
If sym_exact is true, then the output symbol must match the input exactly, otherwise we do a substring match."""
|
|
|
|
command = 'breakpoint set -n "%s"' % (symbol)
|
2013-01-08 08:01:36 +08:00
|
|
|
|
|
|
|
if module_name:
|
|
|
|
command += " --shlib '%s'" % (module_name)
|
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
if extra_options:
|
|
|
|
command += " " + extra_options
|
|
|
|
|
|
|
|
break_results = run_break_set_command(test, command)
|
|
|
|
|
|
|
|
if num_expected_locations == 1 and sym_exact:
|
|
|
|
check_breakpoint_result(
|
|
|
|
test,
|
|
|
|
break_results,
|
|
|
|
num_locations=num_expected_locations,
|
|
|
|
symbol_name=symbol,
|
|
|
|
module_name=module_name)
|
|
|
|
else:
|
|
|
|
check_breakpoint_result(
|
|
|
|
test,
|
|
|
|
break_results,
|
|
|
|
num_locations=num_expected_locations)
|
|
|
|
|
|
|
|
return get_bpno_from_match(break_results)
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
def run_break_set_by_selector(
|
|
|
|
test,
|
|
|
|
selector,
|
|
|
|
extra_options=None,
|
|
|
|
num_expected_locations=-1,
|
|
|
|
module_name=None):
|
|
|
|
"""Set a breakpoint by selector. Common options are the same as run_break_set_by_file_and_line."""
|
|
|
|
|
2013-01-08 08:01:36 +08:00
|
|
|
command = 'breakpoint set -S "%s"' % (selector)
|
|
|
|
|
|
|
|
if module_name:
|
|
|
|
command += ' --shlib "%s"' % (module_name)
|
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
if extra_options:
|
|
|
|
command += " " + extra_options
|
|
|
|
|
|
|
|
break_results = run_break_set_command(test, command)
|
|
|
|
|
|
|
|
if num_expected_locations == 1:
|
|
|
|
check_breakpoint_result(
|
|
|
|
test,
|
|
|
|
break_results,
|
|
|
|
num_locations=num_expected_locations,
|
|
|
|
symbol_name=selector,
|
|
|
|
symbol_match_exact=False,
|
|
|
|
module_name=module_name)
|
|
|
|
else:
|
|
|
|
check_breakpoint_result(
|
|
|
|
test,
|
|
|
|
break_results,
|
|
|
|
num_locations=num_expected_locations)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
return get_bpno_from_match(break_results)
|
|
|
|
|
|
|
|
|
|
|
|
def run_break_set_by_regexp(
|
|
|
|
test,
|
|
|
|
regexp,
|
|
|
|
extra_options=None,
|
|
|
|
num_expected_locations=-1):
|
|
|
|
"""Set a breakpoint by regular expression match on symbol name. Common options are the same as run_break_set_by_file_and_line."""
|
|
|
|
|
|
|
|
command = 'breakpoint set -r "%s"' % (regexp)
|
|
|
|
if extra_options:
|
|
|
|
command += " " + extra_options
|
|
|
|
|
|
|
|
break_results = run_break_set_command(test, command)
|
|
|
|
|
|
|
|
check_breakpoint_result(
|
|
|
|
test,
|
|
|
|
break_results,
|
|
|
|
num_locations=num_expected_locations)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
return get_bpno_from_match(break_results)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
def run_break_set_by_source_regexp(
|
2016-09-07 04:57:50 +08:00
|
|
|
test,
|
2012-09-22 08:05:11 +08:00
|
|
|
regexp,
|
|
|
|
extra_options=None,
|
|
|
|
num_expected_locations=-1):
|
|
|
|
"""Set a breakpoint by source regular expression. Common options are the same as run_break_set_by_file_and_line."""
|
|
|
|
command = 'breakpoint set -p "%s"' % (regexp)
|
|
|
|
if extra_options:
|
|
|
|
command += " " + extra_options
|
|
|
|
|
|
|
|
break_results = run_break_set_command(test, command)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
check_breakpoint_result(
|
2016-09-07 04:57:50 +08:00
|
|
|
test,
|
2012-09-22 08:05:11 +08:00
|
|
|
break_results,
|
|
|
|
num_locations=num_expected_locations)
|
|
|
|
|
|
|
|
return get_bpno_from_match(break_results)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-07-17 02:34:50 +08:00
|
|
|
def run_break_set_by_file_colon_line(
|
|
|
|
test,
|
|
|
|
specifier,
|
|
|
|
path,
|
|
|
|
line_number,
|
|
|
|
column_number = 0,
|
|
|
|
extra_options=None,
|
|
|
|
num_expected_locations=-1):
|
|
|
|
command = 'breakpoint set -y "%s"'%(specifier)
|
|
|
|
if extra_options:
|
|
|
|
command += " " + extra_options
|
|
|
|
|
|
|
|
print("About to run: '%s'", command)
|
|
|
|
break_results = run_break_set_command(test, command)
|
|
|
|
check_breakpoint_result(
|
|
|
|
test,
|
|
|
|
break_results,
|
|
|
|
num_locations = num_expected_locations,
|
|
|
|
file_name = path,
|
|
|
|
line_number = line_number,
|
|
|
|
column_number = column_number)
|
2020-08-20 04:25:57 +08:00
|
|
|
|
2020-07-17 02:34:50 +08:00
|
|
|
return get_bpno_from_match(break_results)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
def run_break_set_command(test, command):
|
|
|
|
"""Run the command passed in - it must be some break set variant - and analyze the result.
|
|
|
|
Returns a dictionary of information gleaned from the command-line results.
|
|
|
|
Will assert if the breakpoint setting fails altogether.
|
|
|
|
|
|
|
|
Dictionary will contain:
|
|
|
|
bpno - breakpoint of the newly created breakpoint, -1 on error.
|
|
|
|
num_locations - number of locations set for the breakpoint.
|
|
|
|
|
|
|
|
If there is only one location, the dictionary MAY contain:
|
|
|
|
file - source file name
|
|
|
|
line_no - source line number
|
2020-07-17 02:34:50 +08:00
|
|
|
column - source column number
|
2012-09-22 08:05:11 +08:00
|
|
|
symbol - symbol name
|
|
|
|
inline_symbol - inlined symbol name
|
|
|
|
offset - offset from the original symbol
|
|
|
|
module - module
|
|
|
|
address - address at which the breakpoint was set."""
|
|
|
|
|
|
|
|
patterns = [
|
|
|
|
r"^Breakpoint (?P<bpno>[0-9]+): (?P<num_locations>[0-9]+) locations\.$",
|
|
|
|
r"^Breakpoint (?P<bpno>[0-9]+): (?P<num_locations>no) locations \(pending\)\.",
|
2018-08-30 23:11:00 +08:00
|
|
|
r"^Breakpoint (?P<bpno>[0-9]+): where = (?P<module>.*)`(?P<symbol>[+\-]{0,1}[^+]+)( \+ (?P<offset>[0-9]+)){0,1}( \[inlined\] (?P<inline_symbol>.*)){0,1} at (?P<file>[^:]+):(?P<line_no>[0-9]+)(?P<column>(:[0-9]+)?), address = (?P<address>0x[0-9a-fA-F]+)$",
|
2012-09-22 08:05:11 +08:00
|
|
|
r"^Breakpoint (?P<bpno>[0-9]+): where = (?P<module>.*)`(?P<symbol>.*)( \+ (?P<offset>[0-9]+)){0,1}, address = (?P<address>0x[0-9a-fA-F]+)$"]
|
|
|
|
match_object = test.match(command, patterns)
|
|
|
|
break_results = match_object.groupdict()
|
|
|
|
|
|
|
|
# We always insert the breakpoint number, setting it to -1 if we couldn't find it
|
|
|
|
# Also, make sure it gets stored as an integer.
|
|
|
|
if not 'bpno' in break_results:
|
|
|
|
break_results['bpno'] = -1
|
|
|
|
else:
|
|
|
|
break_results['bpno'] = int(break_results['bpno'])
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
# We always insert the number of locations
|
|
|
|
# If ONE location is set for the breakpoint, then the output doesn't mention locations, but it has to be 1...
|
|
|
|
# We also make sure it is an integer.
|
|
|
|
|
|
|
|
if not 'num_locations' in break_results:
|
|
|
|
num_locations = 1
|
|
|
|
else:
|
|
|
|
num_locations = break_results['num_locations']
|
|
|
|
if num_locations == 'no':
|
|
|
|
num_locations = 0
|
|
|
|
else:
|
|
|
|
num_locations = int(break_results['num_locations'])
|
|
|
|
|
|
|
|
break_results['num_locations'] = num_locations
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
if 'line_no' in break_results:
|
|
|
|
break_results['line_no'] = int(break_results['line_no'])
|
|
|
|
|
|
|
|
return break_results
|
|
|
|
|
|
|
|
|
|
|
|
def get_bpno_from_match(break_results):
|
|
|
|
return int(break_results['bpno'])
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
def check_breakpoint_result(
|
|
|
|
test,
|
|
|
|
break_results,
|
|
|
|
file_name=None,
|
|
|
|
line_number=-1,
|
2020-07-17 02:34:50 +08:00
|
|
|
column_number=0,
|
2012-09-22 08:05:11 +08:00
|
|
|
symbol_name=None,
|
|
|
|
symbol_match_exact=True,
|
|
|
|
module_name=None,
|
|
|
|
offset=-1,
|
|
|
|
num_locations=-1):
|
|
|
|
|
|
|
|
out_num_locations = break_results['num_locations']
|
|
|
|
|
|
|
|
if num_locations == -1:
|
|
|
|
test.assertTrue(out_num_locations > 0,
|
|
|
|
"Expecting one or more locations, got none.")
|
2018-02-22 02:08:23 +08:00
|
|
|
elif num_locations != -2:
|
2012-09-22 08:05:11 +08:00
|
|
|
test.assertTrue(
|
|
|
|
num_locations == out_num_locations,
|
|
|
|
"Expecting %d locations, got %d." %
|
|
|
|
(num_locations,
|
|
|
|
out_num_locations))
|
|
|
|
|
|
|
|
if file_name:
|
|
|
|
out_file_name = ""
|
|
|
|
if 'file' in break_results:
|
|
|
|
out_file_name = break_results['file']
|
|
|
|
test.assertTrue(
|
2018-04-13 22:52:54 +08:00
|
|
|
file_name.endswith(out_file_name),
|
2012-09-22 08:05:11 +08:00
|
|
|
"Breakpoint file name '%s' doesn't match resultant name '%s'." %
|
|
|
|
(file_name,
|
|
|
|
out_file_name))
|
|
|
|
|
|
|
|
if line_number != -1:
|
2015-05-18 21:41:01 +08:00
|
|
|
out_line_number = -1
|
2012-09-22 08:05:11 +08:00
|
|
|
if 'line_no' in break_results:
|
|
|
|
out_line_number = break_results['line_no']
|
|
|
|
|
|
|
|
test.assertTrue(
|
|
|
|
line_number == out_line_number,
|
|
|
|
"Breakpoint line number %s doesn't match resultant line %s." %
|
|
|
|
(line_number,
|
|
|
|
out_line_number))
|
|
|
|
|
2020-07-17 02:34:50 +08:00
|
|
|
if column_number != 0:
|
|
|
|
out_column_number = 0
|
|
|
|
if 'column' in break_results:
|
|
|
|
out_column_number = break_results['column']
|
|
|
|
|
|
|
|
test.assertTrue(
|
|
|
|
column_number == out_column_number,
|
|
|
|
"Breakpoint column number %s doesn't match resultant column %s." %
|
|
|
|
(column_number,
|
|
|
|
out_column_number))
|
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
if symbol_name:
|
|
|
|
out_symbol_name = ""
|
|
|
|
# Look first for the inlined symbol name, otherwise use the symbol
|
|
|
|
# name:
|
|
|
|
if 'inline_symbol' in break_results and break_results['inline_symbol']:
|
|
|
|
out_symbol_name = break_results['inline_symbol']
|
|
|
|
elif 'symbol' in break_results:
|
|
|
|
out_symbol_name = break_results['symbol']
|
|
|
|
|
|
|
|
if symbol_match_exact:
|
|
|
|
test.assertTrue(
|
|
|
|
symbol_name == out_symbol_name,
|
|
|
|
"Symbol name '%s' doesn't match resultant symbol '%s'." %
|
|
|
|
(symbol_name,
|
|
|
|
out_symbol_name))
|
|
|
|
else:
|
|
|
|
test.assertTrue(
|
|
|
|
out_symbol_name.find(symbol_name) != -
|
|
|
|
1,
|
|
|
|
"Symbol name '%s' isn't in resultant symbol '%s'." %
|
|
|
|
(symbol_name,
|
|
|
|
out_symbol_name))
|
|
|
|
|
|
|
|
if module_name:
|
2015-05-18 21:41:01 +08:00
|
|
|
out_module_name = None
|
2012-09-22 08:05:11 +08:00
|
|
|
if 'module' in break_results:
|
|
|
|
out_module_name = break_results['module']
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-22 08:05:11 +08:00
|
|
|
test.assertTrue(
|
|
|
|
module_name.find(out_module_name) != -
|
|
|
|
1,
|
|
|
|
"Symbol module name '%s' isn't in expected module name '%s'." %
|
|
|
|
(out_module_name,
|
|
|
|
module_name))
|
|
|
|
|
2021-11-17 16:37:30 +08:00
|
|
|
def check_breakpoint(
|
|
|
|
test,
|
|
|
|
bpno,
|
|
|
|
expected_locations = None,
|
|
|
|
expected_resolved_count = None,
|
|
|
|
expected_hit_count = None,
|
|
|
|
location_id = None,
|
|
|
|
expected_location_resolved = True,
|
|
|
|
expected_location_hit_count = None):
|
|
|
|
"""
|
|
|
|
Test breakpoint or breakpoint location.
|
|
|
|
Breakpoint resolved count is always checked. If not specified the assumption is that all locations
|
|
|
|
should be resolved.
|
|
|
|
To test a breakpoint location, breakpoint number (bpno) and location_id must be set. In this case
|
|
|
|
the resolved count for a breakpoint is not tested by default. The location is expected to be resolved,
|
|
|
|
unless expected_location_resolved is set to False.
|
|
|
|
test - test context
|
|
|
|
bpno - breakpoint number to test
|
|
|
|
expected_locations - expected number of locations for this breakpoint. If 'None' this parameter is not tested.
|
|
|
|
expected_resolved_count - expected resolved locations number for the breakpoint. If 'None' - all locations should be resolved.
|
|
|
|
expected_hit_count - expected hit count for this breakpoint. If 'None' this parameter is not tested.
|
|
|
|
location_id - If not 'None' sets the location ID for the breakpoint to test.
|
|
|
|
expected_location_resolved - Extected resolved status for the location_id (True/False). Default - True.
|
|
|
|
expected_location_hit_count - Expected hit count for the breakpoint at location_id. Must be set if the location_id parameter is set.
|
|
|
|
"""
|
2021-11-24 19:13:17 +08:00
|
|
|
|
|
|
|
if isinstance(test.target, lldb.SBTarget):
|
|
|
|
target = test.target
|
|
|
|
else:
|
|
|
|
target = test.target()
|
|
|
|
bkpt = target.FindBreakpointByID(bpno)
|
|
|
|
|
2021-11-17 16:37:30 +08:00
|
|
|
test.assertTrue(bkpt.IsValid(), "Breakpoint is not valid.")
|
|
|
|
|
|
|
|
if expected_locations is not None:
|
|
|
|
test.assertEquals(expected_locations, bkpt.GetNumLocations())
|
|
|
|
|
|
|
|
if expected_resolved_count is not None:
|
|
|
|
test.assertEquals(expected_resolved_count, bkpt.GetNumResolvedLocations())
|
|
|
|
else:
|
|
|
|
expected_resolved_count = bkpt.GetNumLocations()
|
|
|
|
if location_id is None:
|
|
|
|
test.assertEquals(expected_resolved_count, bkpt.GetNumResolvedLocations())
|
|
|
|
|
|
|
|
if expected_hit_count is not None:
|
|
|
|
test.assertEquals(expected_hit_count, bkpt.GetHitCount())
|
|
|
|
|
|
|
|
if location_id is not None:
|
|
|
|
loc_bkpt = bkpt.FindLocationByID(location_id)
|
|
|
|
test.assertTrue(loc_bkpt.IsValid(), "Breakpoint location is not valid.")
|
|
|
|
test.assertEquals(loc_bkpt.IsResolved(), expected_location_resolved)
|
|
|
|
if expected_location_hit_count is not None:
|
|
|
|
test.assertEquals(expected_location_hit_count, loc_bkpt.GetHitCount())
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-10-23 05:31:03 +08:00
|
|
|
# ==================================================
|
|
|
|
# Utility functions related to Threads and Processes
|
|
|
|
# ==================================================
|
2010-10-08 06:15:58 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-26 06:04:05 +08:00
|
|
|
def get_stopped_threads(process, reason):
|
2011-05-27 05:53:05 +08:00
|
|
|
"""Returns the thread(s) with the specified stop reason in a list.
|
|
|
|
|
|
|
|
The list can be empty if no such thread exists.
|
|
|
|
"""
|
2011-04-26 06:04:05 +08:00
|
|
|
threads = []
|
2011-04-29 06:57:01 +08:00
|
|
|
for t in process:
|
2011-04-26 06:04:05 +08:00
|
|
|
if t.GetStopReason() == reason:
|
|
|
|
threads.append(t)
|
|
|
|
return threads
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-26 06:04:05 +08:00
|
|
|
def get_stopped_thread(process, reason):
|
|
|
|
"""A convenience function which returns the first thread with the given stop
|
|
|
|
reason or None.
|
|
|
|
|
|
|
|
Example usages:
|
|
|
|
|
|
|
|
1. Get the stopped thread due to a breakpoint condition
|
|
|
|
|
|
|
|
...
|
|
|
|
from lldbutil import get_stopped_thread
|
2011-06-16 06:14:12 +08:00
|
|
|
thread = get_stopped_thread(process, lldb.eStopReasonPlanComplete)
|
2013-03-20 01:59:30 +08:00
|
|
|
self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition")
|
2011-04-26 06:04:05 +08:00
|
|
|
...
|
|
|
|
|
|
|
|
2. Get the thread stopped due to a breakpoint
|
|
|
|
|
|
|
|
...
|
|
|
|
from lldbutil import get_stopped_thread
|
2011-06-16 06:14:12 +08:00
|
|
|
thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
|
2013-03-20 01:59:30 +08:00
|
|
|
self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint")
|
2011-04-26 06:04:05 +08:00
|
|
|
...
|
|
|
|
|
|
|
|
"""
|
|
|
|
threads = get_stopped_threads(process, reason)
|
|
|
|
if len(threads) == 0:
|
|
|
|
return None
|
|
|
|
return threads[0]
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-01-23 07:54:41 +08:00
|
|
|
def get_threads_stopped_at_breakpoint_id(process, bpid):
|
2011-04-26 07:38:13 +08:00
|
|
|
""" For a stopped process returns the thread stopped at the breakpoint passed in bkpt"""
|
|
|
|
stopped_threads = []
|
|
|
|
threads = []
|
|
|
|
|
|
|
|
stopped_threads = get_stopped_threads(process, lldb.eStopReasonBreakpoint)
|
|
|
|
|
|
|
|
if len(stopped_threads) == 0:
|
|
|
|
return threads
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-26 07:38:13 +08:00
|
|
|
for thread in stopped_threads:
|
2011-12-23 04:21:46 +08:00
|
|
|
# Make sure we've hit our breakpoint...
|
2011-04-26 07:38:13 +08:00
|
|
|
break_id = thread.GetStopReasonDataAtIndex(0)
|
2016-01-23 07:54:41 +08:00
|
|
|
if break_id == bpid:
|
2011-04-26 07:38:13 +08:00
|
|
|
threads.append(thread)
|
|
|
|
|
|
|
|
return threads
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-01-23 07:54:41 +08:00
|
|
|
def get_threads_stopped_at_breakpoint(process, bkpt):
|
|
|
|
return get_threads_stopped_at_breakpoint_id(process, bkpt.GetID())
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-01-23 07:54:41 +08:00
|
|
|
def get_one_thread_stopped_at_breakpoint_id(
|
|
|
|
process, bpid, require_exactly_one=True):
|
|
|
|
threads = get_threads_stopped_at_breakpoint_id(process, bpid)
|
2016-01-22 05:07:30 +08:00
|
|
|
if len(threads) == 0:
|
|
|
|
return None
|
|
|
|
if require_exactly_one and len(threads) != 1:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return threads[0]
|
|
|
|
|
2016-01-23 07:54:41 +08:00
|
|
|
|
|
|
|
def get_one_thread_stopped_at_breakpoint(
|
|
|
|
process, bkpt, require_exactly_one=True):
|
2016-01-23 08:49:11 +08:00
|
|
|
return get_one_thread_stopped_at_breakpoint_id(
|
|
|
|
process, bkpt.GetID(), require_exactly_one)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
|
Report inferior SIGSEGV as a signal instead of an exception on linux
Summary:
Previously, we reported inferior receiving SIGSEGV (or SIGILL, SIGFPE, SIGBUS) as an "exception"
to LLDB, presumably to match OSX behaviour. Beside the fact that we were basically lying to the
user, this was also causing problems with inferiors which handle SIGSEGV by themselves, since
LLDB was unable to reinject this signal back into the inferior.
This commit changes LLGS to report SIGSEGV as a signal. This has necessitated some changes in the
test-suite, which had previously used eStopReasonException to locate threads that crashed. Now it
uses platform-specific logic, which in the case of linux searches for eStopReasonSignaled with
signal=SIGSEGV.
I have also added the ability to set the description of StopInfoUnixSignal using the description
field of the gdb-remote packet. The linux stub uses this to display additional information about
the segfault (invalid address, address access protected, etc.).
Test Plan: All tests pass on linux and osx.
Reviewers: ovyalov, clayborg, emaste
Subscribers: emaste, lldb-commits
Differential Revision: http://reviews.llvm.org/D10057
llvm-svn: 238549
2015-05-29 18:13:03 +08:00
|
|
|
def is_thread_crashed(test, thread):
|
|
|
|
"""In the test suite we dereference a null pointer to simulate a crash. The way this is
|
|
|
|
reported depends on the platform."""
|
|
|
|
if test.platformIsDarwin():
|
|
|
|
return thread.GetStopReason(
|
|
|
|
) == lldb.eStopReasonException and "EXC_BAD_ACCESS" in thread.GetStopDescription(100)
|
|
|
|
elif test.getPlatform() == "linux":
|
|
|
|
return thread.GetStopReason() == lldb.eStopReasonSignal and thread.GetStopReasonDataAtIndex(
|
|
|
|
0) == thread.GetProcess().GetUnixSignals().GetSignalNumberFromName("SIGSEGV")
|
2018-12-03 21:31:13 +08:00
|
|
|
elif test.getPlatform() == "windows":
|
2019-04-29 15:29:25 +08:00
|
|
|
return "Exception 0xc0000005" in thread.GetStopDescription(200)
|
Report inferior SIGSEGV as a signal instead of an exception on linux
Summary:
Previously, we reported inferior receiving SIGSEGV (or SIGILL, SIGFPE, SIGBUS) as an "exception"
to LLDB, presumably to match OSX behaviour. Beside the fact that we were basically lying to the
user, this was also causing problems with inferiors which handle SIGSEGV by themselves, since
LLDB was unable to reinject this signal back into the inferior.
This commit changes LLGS to report SIGSEGV as a signal. This has necessitated some changes in the
test-suite, which had previously used eStopReasonException to locate threads that crashed. Now it
uses platform-specific logic, which in the case of linux searches for eStopReasonSignaled with
signal=SIGSEGV.
I have also added the ability to set the description of StopInfoUnixSignal using the description
field of the gdb-remote packet. The linux stub uses this to display additional information about
the segfault (invalid address, address access protected, etc.).
Test Plan: All tests pass on linux and osx.
Reviewers: ovyalov, clayborg, emaste
Subscribers: emaste, lldb-commits
Differential Revision: http://reviews.llvm.org/D10057
llvm-svn: 238549
2015-05-29 18:13:03 +08:00
|
|
|
else:
|
|
|
|
return "invalid address" in thread.GetStopDescription(100)
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
Report inferior SIGSEGV as a signal instead of an exception on linux
Summary:
Previously, we reported inferior receiving SIGSEGV (or SIGILL, SIGFPE, SIGBUS) as an "exception"
to LLDB, presumably to match OSX behaviour. Beside the fact that we were basically lying to the
user, this was also causing problems with inferiors which handle SIGSEGV by themselves, since
LLDB was unable to reinject this signal back into the inferior.
This commit changes LLGS to report SIGSEGV as a signal. This has necessitated some changes in the
test-suite, which had previously used eStopReasonException to locate threads that crashed. Now it
uses platform-specific logic, which in the case of linux searches for eStopReasonSignaled with
signal=SIGSEGV.
I have also added the ability to set the description of StopInfoUnixSignal using the description
field of the gdb-remote packet. The linux stub uses this to display additional information about
the segfault (invalid address, address access protected, etc.).
Test Plan: All tests pass on linux and osx.
Reviewers: ovyalov, clayborg, emaste
Subscribers: emaste, lldb-commits
Differential Revision: http://reviews.llvm.org/D10057
llvm-svn: 238549
2015-05-29 18:13:03 +08:00
|
|
|
def get_crashed_threads(test, process):
|
|
|
|
threads = []
|
|
|
|
if process.GetState() != lldb.eStateStopped:
|
|
|
|
return threads
|
|
|
|
for thread in process:
|
|
|
|
if is_thread_crashed(test, thread):
|
|
|
|
threads.append(thread)
|
|
|
|
return threads
|
|
|
|
|
2018-02-02 05:35:50 +08:00
|
|
|
# Helper functions for run_to_{source,name}_breakpoint:
|
2017-07-06 10:18:16 +08:00
|
|
|
|
2018-09-14 05:35:32 +08:00
|
|
|
def run_to_breakpoint_make_target(test, exe_name = "a.out", in_cwd = True):
|
2017-07-06 10:18:16 +08:00
|
|
|
if in_cwd:
|
2018-01-20 07:24:35 +08:00
|
|
|
exe = test.getBuildArtifact(exe_name)
|
2018-07-28 06:20:59 +08:00
|
|
|
|
2017-07-06 10:18:16 +08:00
|
|
|
# Create the target
|
|
|
|
target = test.dbg.CreateTarget(exe)
|
|
|
|
test.assertTrue(target, "Target: %s is not valid."%(exe_name))
|
2019-12-12 08:19:08 +08:00
|
|
|
|
|
|
|
# Set environment variables for the inferior.
|
|
|
|
if lldbtest_config.inferior_env:
|
|
|
|
test.runCmd('settings set target.env-vars {}'.format(
|
|
|
|
lldbtest_config.inferior_env))
|
|
|
|
|
2018-02-02 05:35:50 +08:00
|
|
|
return target
|
2017-07-06 10:18:16 +08:00
|
|
|
|
2019-11-08 09:32:29 +08:00
|
|
|
def run_to_breakpoint_do_run(test, target, bkpt, launch_info = None,
|
|
|
|
only_one_thread = True, extra_images = None):
|
2017-07-06 10:18:16 +08:00
|
|
|
|
|
|
|
# Launch the process, and do not stop at the entry point.
|
|
|
|
if not launch_info:
|
2019-12-12 08:19:08 +08:00
|
|
|
launch_info = target.GetLaunchInfo()
|
2017-07-06 10:18:16 +08:00
|
|
|
launch_info.SetWorkingDirectory(test.get_process_working_directory())
|
|
|
|
|
2020-07-07 21:23:49 +08:00
|
|
|
if extra_images:
|
2019-11-08 09:32:29 +08:00
|
|
|
environ = test.registerSharedLibrariesWithTarget(target, extra_images)
|
|
|
|
launch_info.SetEnvironmentEntries(environ, True)
|
|
|
|
|
2017-07-06 10:18:16 +08:00
|
|
|
error = lldb.SBError()
|
|
|
|
process = target.Launch(launch_info, error)
|
|
|
|
|
2020-08-08 04:28:05 +08:00
|
|
|
# Unfortunate workaround for the iPhone simulator.
|
|
|
|
retry = SIMULATOR_RETRY
|
|
|
|
while (retry and error.Fail() and error.GetCString() and
|
|
|
|
"Unable to boot the Simulator" in error.GetCString()):
|
|
|
|
retry -= 1
|
|
|
|
print("** Simulator is unresponsive. Retrying %d more time(s)"%retry)
|
|
|
|
import time
|
|
|
|
time.sleep(60)
|
|
|
|
error = lldb.SBError()
|
|
|
|
process = target.Launch(launch_info, error)
|
|
|
|
|
2018-07-28 06:20:59 +08:00
|
|
|
test.assertTrue(process,
|
2020-08-08 04:28:05 +08:00
|
|
|
"Could not create a valid process for %s: %s" %
|
|
|
|
(target.GetExecutable().GetFilename(), error.GetCString()))
|
2019-12-11 03:18:45 +08:00
|
|
|
test.assertFalse(error.Fail(),
|
|
|
|
"Process launch failed: %s" % (error.GetCString()))
|
2017-07-06 10:18:16 +08:00
|
|
|
|
2020-07-07 21:23:49 +08:00
|
|
|
test.assertEqual(process.GetState(), lldb.eStateStopped)
|
|
|
|
|
2017-07-06 10:18:16 +08:00
|
|
|
# Frame #0 should be at our breakpoint.
|
|
|
|
threads = get_threads_stopped_at_breakpoint(
|
2018-02-02 05:35:50 +08:00
|
|
|
process, bkpt)
|
2017-07-06 10:18:16 +08:00
|
|
|
|
2019-10-29 07:15:09 +08:00
|
|
|
num_threads = len(threads)
|
|
|
|
if only_one_thread:
|
|
|
|
test.assertEqual(num_threads, 1, "Expected 1 thread to stop at breakpoint, %d did."%(num_threads))
|
|
|
|
else:
|
|
|
|
test.assertGreater(num_threads, 0, "No threads stopped at breakpoint")
|
2020-03-14 06:56:35 +08:00
|
|
|
|
2017-07-06 10:18:16 +08:00
|
|
|
thread = threads[0]
|
2018-02-02 05:35:50 +08:00
|
|
|
return (target, process, thread, bkpt)
|
|
|
|
|
2018-07-28 06:20:59 +08:00
|
|
|
def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
|
2018-02-02 05:35:50 +08:00
|
|
|
exe_name = "a.out",
|
2018-02-03 02:39:25 +08:00
|
|
|
bkpt_module = None,
|
2019-10-29 07:15:09 +08:00
|
|
|
in_cwd = True,
|
2019-11-08 09:32:29 +08:00
|
|
|
only_one_thread = True,
|
|
|
|
extra_images = None):
|
2018-02-02 05:35:50 +08:00
|
|
|
"""Start up a target, using exe_name as the executable, and run it to
|
2018-02-03 02:39:25 +08:00
|
|
|
a breakpoint set by name on bkpt_name restricted to bkpt_module.
|
2018-02-02 05:35:50 +08:00
|
|
|
|
|
|
|
If you want to pass in launch arguments or environment
|
|
|
|
variables, you can optionally pass in an SBLaunchInfo. If you
|
|
|
|
do that, remember to set the working directory as well.
|
|
|
|
|
|
|
|
If your executable isn't called a.out, you can pass that in.
|
|
|
|
And if your executable isn't in the CWD, pass in the absolute
|
|
|
|
path to the executable in exe_name, and set in_cwd to False.
|
|
|
|
|
2018-02-03 02:39:25 +08:00
|
|
|
If you need to restrict the breakpoint to a particular module,
|
|
|
|
pass the module name (a string not a FileSpec) in bkpt_module. If
|
|
|
|
nothing is passed in setting will be unrestricted.
|
|
|
|
|
2018-02-02 05:35:50 +08:00
|
|
|
If the target isn't valid, the breakpoint isn't found, or hit, the
|
|
|
|
function will cause a testsuite failure.
|
|
|
|
|
|
|
|
If successful it returns a tuple with the target process and
|
2018-02-03 02:39:25 +08:00
|
|
|
thread that hit the breakpoint, and the breakpoint that we set
|
|
|
|
for you.
|
2019-10-29 07:15:09 +08:00
|
|
|
|
|
|
|
If only_one_thread is true, we require that there be only one
|
|
|
|
thread stopped at the breakpoint. Otherwise we only require one
|
|
|
|
or more threads stop there. If there are more than one, we return
|
|
|
|
the first thread that stopped.
|
2018-02-02 05:35:50 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
target = run_to_breakpoint_make_target(test, exe_name, in_cwd)
|
|
|
|
|
2018-02-03 02:39:25 +08:00
|
|
|
breakpoint = target.BreakpointCreateByName(bkpt_name, bkpt_module)
|
|
|
|
|
|
|
|
|
2018-02-02 05:35:50 +08:00
|
|
|
test.assertTrue(breakpoint.GetNumLocations() > 0,
|
|
|
|
"No locations found for name breakpoint: '%s'."%(bkpt_name))
|
2019-11-08 09:32:29 +08:00
|
|
|
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info,
|
|
|
|
only_one_thread, extra_images)
|
2018-02-02 05:35:50 +08:00
|
|
|
|
|
|
|
def run_to_source_breakpoint(test, bkpt_pattern, source_spec,
|
|
|
|
launch_info = None, exe_name = "a.out",
|
2018-02-03 02:39:25 +08:00
|
|
|
bkpt_module = None,
|
2019-10-29 07:15:09 +08:00
|
|
|
in_cwd = True,
|
2019-11-08 09:32:29 +08:00
|
|
|
only_one_thread = True,
|
2021-10-16 09:37:47 +08:00
|
|
|
extra_images = None,
|
|
|
|
has_locations_before_run = True):
|
2018-02-02 05:35:50 +08:00
|
|
|
"""Start up a target, using exe_name as the executable, and run it to
|
|
|
|
a breakpoint set by source regex bkpt_pattern.
|
|
|
|
|
|
|
|
The rest of the behavior is the same as run_to_name_breakpoint.
|
|
|
|
"""
|
|
|
|
|
|
|
|
target = run_to_breakpoint_make_target(test, exe_name, in_cwd)
|
|
|
|
# Set the breakpoints
|
|
|
|
breakpoint = target.BreakpointCreateBySourceRegex(
|
2018-02-03 02:39:25 +08:00
|
|
|
bkpt_pattern, source_spec, bkpt_module)
|
2021-10-16 09:37:47 +08:00
|
|
|
if has_locations_before_run:
|
|
|
|
test.assertTrue(breakpoint.GetNumLocations() > 0,
|
|
|
|
'No locations found for source breakpoint: "%s", file: "%s", dir: "%s"'
|
|
|
|
%(bkpt_pattern, source_spec.GetFilename(), source_spec.GetDirectory()))
|
2019-11-08 09:32:29 +08:00
|
|
|
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info,
|
|
|
|
only_one_thread, extra_images)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-08-30 23:11:00 +08:00
|
|
|
def run_to_line_breakpoint(test, source_spec, line_number, column = 0,
|
|
|
|
launch_info = None, exe_name = "a.out",
|
|
|
|
bkpt_module = None,
|
2019-10-29 07:15:09 +08:00
|
|
|
in_cwd = True,
|
2019-11-08 09:32:29 +08:00
|
|
|
only_one_thread = True,
|
|
|
|
extra_images = None):
|
2018-08-30 23:11:00 +08:00
|
|
|
"""Start up a target, using exe_name as the executable, and run it to
|
|
|
|
a breakpoint set by (source_spec, line_number(, column)).
|
|
|
|
|
|
|
|
The rest of the behavior is the same as run_to_name_breakpoint.
|
|
|
|
"""
|
|
|
|
|
|
|
|
target = run_to_breakpoint_make_target(test, exe_name, in_cwd)
|
|
|
|
# Set the breakpoints
|
|
|
|
breakpoint = target.BreakpointCreateByLocation(
|
|
|
|
source_spec, line_number, column, 0, lldb.SBFileSpecList())
|
|
|
|
test.assertTrue(breakpoint.GetNumLocations() > 0,
|
|
|
|
'No locations found for line breakpoint: "%s:%d(:%d)", dir: "%s"'
|
|
|
|
%(source_spec.GetFilename(), line_number, column,
|
|
|
|
source_spec.GetDirectory()))
|
2019-11-08 09:32:29 +08:00
|
|
|
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info,
|
|
|
|
only_one_thread, extra_images)
|
2018-08-30 23:11:00 +08:00
|
|
|
|
|
|
|
|
2011-04-26 07:38:13 +08:00
|
|
|
def continue_to_breakpoint(process, bkpt):
|
|
|
|
""" Continues the process, if it stops, returns the threads stopped at bkpt; otherwise, returns None"""
|
|
|
|
process.Continue()
|
|
|
|
if process.GetState() != lldb.eStateStopped:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return get_threads_stopped_at_breakpoint(process, bkpt)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-26 07:38:13 +08:00
|
|
|
|
2011-03-10 07:45:56 +08:00
|
|
|
def get_caller_symbol(thread):
|
|
|
|
"""
|
|
|
|
Returns the symbol name for the call site of the leaf function.
|
|
|
|
"""
|
|
|
|
depth = thread.GetNumFrames()
|
|
|
|
if depth <= 1:
|
|
|
|
return None
|
|
|
|
caller = thread.GetFrameAtIndex(1).GetSymbol()
|
|
|
|
if caller:
|
|
|
|
return caller.GetName()
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2011-04-26 07:38:13 +08:00
|
|
|
def get_function_names(thread):
|
2010-09-09 06:54:46 +08:00
|
|
|
"""
|
|
|
|
Returns a sequence of function names from the stack frames of this thread.
|
|
|
|
"""
|
|
|
|
def GetFuncName(i):
|
2011-06-20 08:26:39 +08:00
|
|
|
return thread.GetFrameAtIndex(i).GetFunctionName()
|
2010-09-09 06:54:46 +08:00
|
|
|
|
2015-10-27 00:49:57 +08:00
|
|
|
return list(map(GetFuncName, list(range(thread.GetNumFrames()))))
|
2010-09-09 06:54:46 +08:00
|
|
|
|
|
|
|
|
2011-04-26 07:38:13 +08:00
|
|
|
def get_symbol_names(thread):
|
2010-10-08 05:38:28 +08:00
|
|
|
"""
|
|
|
|
Returns a sequence of symbols for this thread.
|
|
|
|
"""
|
|
|
|
def GetSymbol(i):
|
|
|
|
return thread.GetFrameAtIndex(i).GetSymbol().GetName()
|
|
|
|
|
2015-10-27 00:49:57 +08:00
|
|
|
return list(map(GetSymbol, list(range(thread.GetNumFrames()))))
|
2010-10-08 05:38:28 +08:00
|
|
|
|
|
|
|
|
2011-04-26 07:38:13 +08:00
|
|
|
def get_pc_addresses(thread):
|
2010-10-08 05:38:28 +08:00
|
|
|
"""
|
|
|
|
Returns a sequence of pc addresses for this thread.
|
|
|
|
"""
|
|
|
|
def GetPCAddress(i):
|
|
|
|
return thread.GetFrameAtIndex(i).GetPCAddress()
|
|
|
|
|
2015-10-27 00:49:57 +08:00
|
|
|
return list(map(GetPCAddress, list(range(thread.GetNumFrames()))))
|
2010-10-08 05:38:28 +08:00
|
|
|
|
|
|
|
|
2011-04-26 07:38:13 +08:00
|
|
|
def get_filenames(thread):
|
2010-09-09 06:54:46 +08:00
|
|
|
"""
|
|
|
|
Returns a sequence of file names from the stack frames of this thread.
|
|
|
|
"""
|
|
|
|
def GetFilename(i):
|
|
|
|
return thread.GetFrameAtIndex(
|
|
|
|
i).GetLineEntry().GetFileSpec().GetFilename()
|
|
|
|
|
2015-10-27 00:49:57 +08:00
|
|
|
return list(map(GetFilename, list(range(thread.GetNumFrames()))))
|
2010-09-09 06:54:46 +08:00
|
|
|
|
|
|
|
|
2011-04-26 07:38:13 +08:00
|
|
|
def get_line_numbers(thread):
|
2010-09-09 06:54:46 +08:00
|
|
|
"""
|
|
|
|
Returns a sequence of line numbers from the stack frames of this thread.
|
|
|
|
"""
|
|
|
|
def GetLineNumber(i):
|
|
|
|
return thread.GetFrameAtIndex(i).GetLineEntry().GetLine()
|
|
|
|
|
2015-10-27 00:49:57 +08:00
|
|
|
return list(map(GetLineNumber, list(range(thread.GetNumFrames()))))
|
2010-09-09 06:54:46 +08:00
|
|
|
|
|
|
|
|
2011-04-26 07:38:13 +08:00
|
|
|
def get_module_names(thread):
|
2010-09-09 06:54:46 +08:00
|
|
|
"""
|
|
|
|
Returns a sequence of module names from the stack frames of this thread.
|
|
|
|
"""
|
|
|
|
def GetModuleName(i):
|
|
|
|
return thread.GetFrameAtIndex(
|
|
|
|
i).GetModule().GetFileSpec().GetFilename()
|
|
|
|
|
2015-10-27 00:49:57 +08:00
|
|
|
return list(map(GetModuleName, list(range(thread.GetNumFrames()))))
|
2010-09-09 06:54:46 +08:00
|
|
|
|
|
|
|
|
2011-04-26 07:38:13 +08:00
|
|
|
def get_stack_frames(thread):
|
2010-09-09 08:55:07 +08:00
|
|
|
"""
|
|
|
|
Returns a sequence of stack frames for this thread.
|
|
|
|
"""
|
|
|
|
def GetStackFrame(i):
|
|
|
|
return thread.GetFrameAtIndex(i)
|
|
|
|
|
2015-10-27 00:49:57 +08:00
|
|
|
return list(map(GetStackFrame, list(range(thread.GetNumFrames()))))
|
2010-09-09 08:55:07 +08:00
|
|
|
|
|
|
|
|
2011-04-26 07:38:13 +08:00
|
|
|
def print_stacktrace(thread, string_buffer=False):
|
2010-09-09 06:54:46 +08:00
|
|
|
"""Prints a simple stack trace of this thread."""
|
2010-10-08 02:52:48 +08:00
|
|
|
|
2015-10-22 01:48:52 +08:00
|
|
|
output = SixStringIO() if string_buffer else sys.stdout
|
2010-10-08 05:38:28 +08:00
|
|
|
target = thread.GetProcess().GetTarget()
|
|
|
|
|
2010-09-09 06:54:46 +08:00
|
|
|
depth = thread.GetNumFrames()
|
|
|
|
|
2011-04-26 07:38:13 +08:00
|
|
|
mods = get_module_names(thread)
|
|
|
|
funcs = get_function_names(thread)
|
|
|
|
symbols = get_symbol_names(thread)
|
|
|
|
files = get_filenames(thread)
|
|
|
|
lines = get_line_numbers(thread)
|
|
|
|
addrs = get_pc_addresses(thread)
|
2010-10-08 02:52:48 +08:00
|
|
|
|
2010-10-26 03:13:52 +08:00
|
|
|
if thread.GetStopReason() != lldb.eStopReasonInvalid:
|
2011-04-28 01:43:07 +08:00
|
|
|
desc = "stop reason=" + stop_reason_to_str(thread.GetStopReason())
|
2010-10-26 03:13:52 +08:00
|
|
|
else:
|
|
|
|
desc = ""
|
2015-10-20 07:45:41 +08:00
|
|
|
print(
|
|
|
|
"Stack trace for thread id={0:#x} name={1} queue={2} ".format(
|
|
|
|
thread.GetThreadID(),
|
|
|
|
thread.GetName(),
|
|
|
|
thread.GetQueueName()) + desc,
|
|
|
|
file=output)
|
2010-09-09 06:54:46 +08:00
|
|
|
|
2010-10-08 05:38:28 +08:00
|
|
|
for i in range(depth):
|
|
|
|
frame = thread.GetFrameAtIndex(i)
|
|
|
|
function = frame.GetFunction()
|
|
|
|
|
|
|
|
load_addr = addrs[i].GetLoadAddress(target)
|
2011-05-26 03:06:18 +08:00
|
|
|
if not function:
|
2010-10-08 05:38:28 +08:00
|
|
|
file_addr = addrs[i].GetFileAddress()
|
2011-06-17 06:07:48 +08:00
|
|
|
start_addr = frame.GetSymbol().GetStartAddress().GetFileAddress()
|
|
|
|
symbol_offset = file_addr - start_addr
|
2015-10-20 07:45:41 +08:00
|
|
|
print(
|
|
|
|
" frame #{num}: {addr:#016x} {mod}`{symbol} + {offset}".format(
|
|
|
|
num=i,
|
|
|
|
addr=load_addr,
|
|
|
|
mod=mods[i],
|
|
|
|
symbol=symbols[i],
|
|
|
|
offset=symbol_offset),
|
|
|
|
file=output)
|
2010-10-08 05:38:28 +08:00
|
|
|
else:
|
2015-10-20 07:45:41 +08:00
|
|
|
print(
|
|
|
|
" frame #{num}: {addr:#016x} {mod}`{func} at {file}:{line} {args}".format(
|
2011-06-20 08:26:39 +08:00
|
|
|
num=i,
|
|
|
|
addr=load_addr,
|
|
|
|
mod=mods[i],
|
|
|
|
func='%s [inlined]' %
|
|
|
|
funcs[i] if frame.IsInlined() else funcs[i],
|
2011-07-14 06:34:29 +08:00
|
|
|
file=files[i],
|
|
|
|
line=lines[i],
|
2015-10-20 07:45:41 +08:00
|
|
|
args=get_args_as_string(
|
|
|
|
frame,
|
|
|
|
showFuncName=False) if not frame.IsInlined() else '()'),
|
|
|
|
file=output)
|
2010-10-08 05:38:28 +08:00
|
|
|
|
|
|
|
if string_buffer:
|
2010-10-16 07:33:18 +08:00
|
|
|
return output.getvalue()
|
2010-10-08 05:38:28 +08:00
|
|
|
|
|
|
|
|
2011-04-26 07:38:13 +08:00
|
|
|
def print_stacktraces(process, string_buffer=False):
|
2010-10-08 05:38:28 +08:00
|
|
|
"""Prints the stack traces of all the threads."""
|
|
|
|
|
2015-10-22 01:48:52 +08:00
|
|
|
output = SixStringIO() if string_buffer else sys.stdout
|
2010-10-08 05:38:28 +08:00
|
|
|
|
2015-10-20 07:45:41 +08:00
|
|
|
print("Stack traces for " + str(process), file=output)
|
2010-09-09 06:54:46 +08:00
|
|
|
|
2011-05-06 02:50:56 +08:00
|
|
|
for thread in process:
|
2015-10-20 07:45:41 +08:00
|
|
|
print(print_stacktrace(thread, string_buffer=True), file=output)
|
2010-10-08 02:52:48 +08:00
|
|
|
|
|
|
|
if string_buffer:
|
2010-10-16 07:33:18 +08:00
|
|
|
return output.getvalue()
|
2011-05-09 01:25:27 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-03-07 01:59:45 +08:00
|
|
|
def expect_state_changes(test, listener, process, states, timeout=30):
|
2015-09-02 17:12:28 +08:00
|
|
|
"""Listens for state changed events on the listener and makes sure they match what we
|
|
|
|
expect. Stop-and-restart events (where GetRestartedFromEvent() returns true) are ignored."""
|
|
|
|
|
2016-01-06 19:40:06 +08:00
|
|
|
for expected_state in states:
|
|
|
|
def get_next_event():
|
|
|
|
event = lldb.SBEvent()
|
2016-04-14 23:52:58 +08:00
|
|
|
if not listener.WaitForEventForBroadcasterWithType(
|
|
|
|
timeout,
|
|
|
|
process.GetBroadcaster(),
|
|
|
|
lldb.SBProcess.eBroadcastBitStateChanged,
|
|
|
|
event):
|
2016-01-06 19:40:06 +08:00
|
|
|
test.fail(
|
|
|
|
"Timed out while waiting for a transition to state %s" %
|
|
|
|
lldb.SBDebugger.StateAsCString(expected_state))
|
|
|
|
return event
|
|
|
|
|
|
|
|
event = get_next_event()
|
|
|
|
while (lldb.SBProcess.GetStateFromEvent(event) == lldb.eStateStopped and
|
|
|
|
lldb.SBProcess.GetRestartedFromEvent(event)):
|
|
|
|
# Ignore restarted event and the subsequent running event.
|
|
|
|
event = get_next_event()
|
|
|
|
test.assertEqual(
|
|
|
|
lldb.SBProcess.GetStateFromEvent(event),
|
|
|
|
lldb.eStateRunning,
|
|
|
|
"Restarted event followed by a running event")
|
|
|
|
event = get_next_event()
|
|
|
|
|
|
|
|
test.assertEqual(
|
|
|
|
lldb.SBProcess.GetStateFromEvent(event),
|
|
|
|
expected_state)
|
2015-09-02 17:12:28 +08:00
|
|
|
|
2011-05-09 01:25:27 +08:00
|
|
|
# ===================================
|
|
|
|
# Utility functions related to Frames
|
|
|
|
# ===================================
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-05-12 08:32:41 +08:00
|
|
|
def get_parent_frame(frame):
|
|
|
|
"""
|
|
|
|
Returns the parent frame of the input frame object; None if not available.
|
|
|
|
"""
|
|
|
|
thread = frame.GetThread()
|
|
|
|
parent_found = False
|
|
|
|
for f in thread:
|
|
|
|
if parent_found:
|
|
|
|
return f
|
|
|
|
if f.GetFrameID() == frame.GetFrameID():
|
|
|
|
parent_found = True
|
|
|
|
|
|
|
|
# If we reach here, no parent has been found, return None.
|
|
|
|
return None
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-06-17 06:07:48 +08:00
|
|
|
def get_args_as_string(frame, showFuncName=True):
|
2011-05-12 08:32:41 +08:00
|
|
|
"""
|
|
|
|
Returns the args of the input frame object as a string.
|
|
|
|
"""
|
|
|
|
# arguments => True
|
|
|
|
# locals => False
|
|
|
|
# statics => False
|
|
|
|
# in_scope_only => True
|
|
|
|
vars = frame.GetVariables(True, False, False, True) # type of SBValueList
|
|
|
|
args = [] # list of strings
|
|
|
|
for var in vars:
|
|
|
|
args.append("(%s)%s=%s" % (var.GetTypeName(),
|
|
|
|
var.GetName(),
|
2011-08-04 06:57:10 +08:00
|
|
|
var.GetValue()))
|
2011-05-26 03:06:18 +08:00
|
|
|
if frame.GetFunction():
|
2011-05-13 08:44:49 +08:00
|
|
|
name = frame.GetFunction().GetName()
|
2011-05-26 03:06:18 +08:00
|
|
|
elif frame.GetSymbol():
|
2011-05-13 08:44:49 +08:00
|
|
|
name = frame.GetSymbol().GetName()
|
|
|
|
else:
|
|
|
|
name = ""
|
2011-06-17 06:07:48 +08:00
|
|
|
if showFuncName:
|
|
|
|
return "%s(%s)" % (name, ", ".join(args))
|
|
|
|
else:
|
|
|
|
return "(%s)" % (", ".join(args))
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
|
2011-05-09 01:25:27 +08:00
|
|
|
def print_registers(frame, string_buffer=False):
|
2011-05-09 02:55:37 +08:00
|
|
|
"""Prints all the register sets of the frame."""
|
2011-05-09 01:25:27 +08:00
|
|
|
|
2015-10-22 01:48:52 +08:00
|
|
|
output = SixStringIO() if string_buffer else sys.stdout
|
2011-05-09 01:25:27 +08:00
|
|
|
|
2015-10-20 07:45:41 +08:00
|
|
|
print("Register sets for " + str(frame), file=output)
|
2011-05-09 01:25:27 +08:00
|
|
|
|
2011-05-11 03:21:13 +08:00
|
|
|
registerSet = frame.GetRegisters() # Return type of SBValueList.
|
2015-10-20 07:45:41 +08:00
|
|
|
print("Frame registers (size of register set = %d):" %
|
|
|
|
registerSet.GetSize(), file=output)
|
2011-05-11 03:21:13 +08:00
|
|
|
for value in registerSet:
|
2015-10-24 01:04:29 +08:00
|
|
|
#print(value, file=output)
|
2015-10-20 07:45:41 +08:00
|
|
|
print("%s (number of children = %d):" %
|
|
|
|
(value.GetName(), value.GetNumChildren()), file=output)
|
2011-05-09 01:25:27 +08:00
|
|
|
for child in value:
|
2015-10-20 07:45:41 +08:00
|
|
|
print(
|
|
|
|
"Name: %s, Value: %s" %
|
|
|
|
(child.GetName(),
|
|
|
|
child.GetValue()),
|
|
|
|
file=output)
|
2011-05-09 01:25:27 +08:00
|
|
|
|
|
|
|
if string_buffer:
|
|
|
|
return output.getvalue()
|
2011-05-11 03:21:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-05-11 03:21:13 +08:00
|
|
|
def get_registers(frame, kind):
|
|
|
|
"""Returns the registers given the frame and the kind of registers desired.
|
|
|
|
|
|
|
|
Returns None if there's no such kind.
|
|
|
|
"""
|
|
|
|
registerSet = frame.GetRegisters() # Return type of SBValueList.
|
|
|
|
for value in registerSet:
|
|
|
|
if kind.lower() in value.GetName().lower():
|
|
|
|
return value
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-05-11 03:21:13 +08:00
|
|
|
def get_GPRs(frame):
|
|
|
|
"""Returns the general purpose registers of the frame as an SBValue.
|
|
|
|
|
2011-05-11 07:01:44 +08:00
|
|
|
The returned SBValue object is iterable. An example:
|
|
|
|
...
|
|
|
|
from lldbutil import get_GPRs
|
|
|
|
regs = get_GPRs(frame)
|
|
|
|
for reg in regs:
|
2015-10-24 01:04:29 +08:00
|
|
|
print("%s => %s" % (reg.GetName(), reg.GetValue()))
|
2011-05-11 07:01:44 +08:00
|
|
|
...
|
2011-05-11 03:21:13 +08:00
|
|
|
"""
|
|
|
|
return get_registers(frame, "general purpose")
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-05-11 03:21:13 +08:00
|
|
|
def get_FPRs(frame):
|
|
|
|
"""Returns the floating point registers of the frame as an SBValue.
|
|
|
|
|
2011-05-11 07:01:44 +08:00
|
|
|
The returned SBValue object is iterable. An example:
|
|
|
|
...
|
|
|
|
from lldbutil import get_FPRs
|
|
|
|
regs = get_FPRs(frame)
|
|
|
|
for reg in regs:
|
2015-10-24 01:04:29 +08:00
|
|
|
print("%s => %s" % (reg.GetName(), reg.GetValue()))
|
2011-05-11 07:01:44 +08:00
|
|
|
...
|
2011-05-11 03:21:13 +08:00
|
|
|
"""
|
|
|
|
return get_registers(frame, "floating point")
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-05-11 03:21:13 +08:00
|
|
|
def get_ESRs(frame):
|
|
|
|
"""Returns the exception state registers of the frame as an SBValue.
|
|
|
|
|
2011-05-11 07:01:44 +08:00
|
|
|
The returned SBValue object is iterable. An example:
|
|
|
|
...
|
|
|
|
from lldbutil import get_ESRs
|
|
|
|
regs = get_ESRs(frame)
|
|
|
|
for reg in regs:
|
2015-10-24 01:04:29 +08:00
|
|
|
print("%s => %s" % (reg.GetName(), reg.GetValue()))
|
2011-05-11 07:01:44 +08:00
|
|
|
...
|
2011-05-11 03:21:13 +08:00
|
|
|
"""
|
|
|
|
return get_registers(frame, "exception state")
|
2011-07-22 08:47:58 +08:00
|
|
|
|
2011-07-22 08:51:54 +08:00
|
|
|
# ======================================
|
|
|
|
# Utility classes/functions for SBValues
|
|
|
|
# ======================================
|
2011-07-22 08:47:58 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-22 08:47:58 +08:00
|
|
|
class BasicFormatter(object):
|
2011-07-23 06:01:35 +08:00
|
|
|
"""The basic formatter inspects the value object and prints the value."""
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-22 08:47:58 +08:00
|
|
|
def format(self, value, buffer=None, indent=0):
|
|
|
|
if not buffer:
|
2015-10-22 01:48:52 +08:00
|
|
|
output = SixStringIO()
|
2011-07-22 08:47:58 +08:00
|
|
|
else:
|
|
|
|
output = buffer
|
2011-07-23 06:01:35 +08:00
|
|
|
# If there is a summary, it suffices.
|
|
|
|
val = value.GetSummary()
|
|
|
|
# Otherwise, get the value.
|
|
|
|
if val is None:
|
|
|
|
val = value.GetValue()
|
|
|
|
if val is None and value.GetNumChildren() > 0:
|
|
|
|
val = "%s (location)" % value.GetLocation()
|
2015-10-20 07:45:41 +08:00
|
|
|
print("{indentation}({type}) {name} = {value}".format(
|
2011-07-22 08:47:58 +08:00
|
|
|
indentation=' ' * indent,
|
|
|
|
type=value.GetTypeName(),
|
|
|
|
name=value.GetName(),
|
2015-10-20 07:45:41 +08:00
|
|
|
value=val), file=output)
|
2011-07-22 08:47:58 +08:00
|
|
|
return output.getvalue()
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-22 08:47:58 +08:00
|
|
|
class ChildVisitingFormatter(BasicFormatter):
|
2011-07-23 06:01:35 +08:00
|
|
|
"""The child visiting formatter prints the value and its immediate children.
|
|
|
|
|
|
|
|
The constructor takes a keyword arg: indent_child, which defaults to 2.
|
|
|
|
"""
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-23 06:01:35 +08:00
|
|
|
def __init__(self, indent_child=2):
|
|
|
|
"""Default indentation of 2 SPC's for the children."""
|
|
|
|
self.cindent = indent_child
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-22 08:47:58 +08:00
|
|
|
def format(self, value, buffer=None):
|
|
|
|
if not buffer:
|
2015-10-22 01:48:52 +08:00
|
|
|
output = SixStringIO()
|
2011-07-22 08:47:58 +08:00
|
|
|
else:
|
|
|
|
output = buffer
|
|
|
|
|
|
|
|
BasicFormatter.format(self, value, buffer=output)
|
|
|
|
for child in value:
|
2011-07-23 06:01:35 +08:00
|
|
|
BasicFormatter.format(
|
|
|
|
self, child, buffer=output, indent=self.cindent)
|
|
|
|
|
|
|
|
return output.getvalue()
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-23 06:01:35 +08:00
|
|
|
class RecursiveDecentFormatter(BasicFormatter):
|
|
|
|
"""The recursive decent formatter prints the value and the decendents.
|
|
|
|
|
|
|
|
The constructor takes two keyword args: indent_level, which defaults to 0,
|
|
|
|
and indent_child, which defaults to 2. The current indentation level is
|
|
|
|
determined by indent_level, while the immediate children has an additional
|
|
|
|
indentation by inden_child.
|
|
|
|
"""
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-23 06:01:35 +08:00
|
|
|
def __init__(self, indent_level=0, indent_child=2):
|
|
|
|
self.lindent = indent_level
|
|
|
|
self.cindent = indent_child
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-23 06:01:35 +08:00
|
|
|
def format(self, value, buffer=None):
|
|
|
|
if not buffer:
|
2015-10-22 01:48:52 +08:00
|
|
|
output = SixStringIO()
|
2011-07-23 06:01:35 +08:00
|
|
|
else:
|
|
|
|
output = buffer
|
|
|
|
|
|
|
|
BasicFormatter.format(self, value, buffer=output, indent=self.lindent)
|
|
|
|
new_indent = self.lindent + self.cindent
|
|
|
|
for child in value:
|
|
|
|
if child.GetSummary() is not None:
|
|
|
|
BasicFormatter.format(
|
|
|
|
self, child, buffer=output, indent=new_indent)
|
|
|
|
else:
|
|
|
|
if child.GetNumChildren() > 0:
|
|
|
|
rdf = RecursiveDecentFormatter(indent_level=new_indent)
|
|
|
|
rdf.format(child, buffer=output)
|
|
|
|
else:
|
|
|
|
BasicFormatter.format(
|
|
|
|
self, child, buffer=output, indent=new_indent)
|
2011-07-22 08:47:58 +08:00
|
|
|
|
|
|
|
return output.getvalue()
|
2015-05-12 01:53:39 +08:00
|
|
|
|
|
|
|
# ===========================================================
|
|
|
|
# Utility functions for path manipulation on remote platforms
|
|
|
|
# ===========================================================
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-05-12 01:53:39 +08:00
|
|
|
def join_remote_paths(*paths):
|
|
|
|
# TODO: update with actual platform name for remote windows once it exists
|
|
|
|
if lldb.remote_platform.GetName() == 'remote-windows':
|
|
|
|
return os.path.join(*paths).replace(os.path.sep, '\\')
|
|
|
|
return os.path.join(*paths).replace(os.path.sep, '/')
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-02-21 23:33:53 +08:00
|
|
|
def append_to_process_working_directory(test, *paths):
|
2015-06-06 08:25:50 +08:00
|
|
|
remote = lldb.remote_platform
|
|
|
|
if remote:
|
|
|
|
return join_remote_paths(remote.GetWorkingDirectory(), *paths)
|
2018-02-21 23:33:53 +08:00
|
|
|
return os.path.join(test.getBuildDir(), *paths)
|
2015-06-03 00:46:28 +08:00
|
|
|
|
|
|
|
# ==================================================
|
|
|
|
# Utility functions to get the correct signal number
|
|
|
|
# ==================================================
|
|
|
|
|
|
|
|
import signal
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-06-03 00:46:28 +08:00
|
|
|
def get_signal_number(signal_name):
|
|
|
|
platform = lldb.remote_platform
|
2015-07-14 09:09:28 +08:00
|
|
|
if platform and platform.IsValid():
|
|
|
|
signals = platform.GetUnixSignals()
|
|
|
|
if signals.IsValid():
|
2015-06-03 02:31:57 +08:00
|
|
|
signal_number = signals.GetSignalNumberFromName(signal_name)
|
|
|
|
if signal_number > 0:
|
|
|
|
return signal_number
|
2015-07-14 09:09:28 +08:00
|
|
|
# No remote platform; fall back to using local python signals.
|
2015-06-03 00:46:28 +08:00
|
|
|
return getattr(signal, signal_name)
|
2015-09-19 04:12:52 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-19 04:12:52 +08:00
|
|
|
class PrintableRegex(object):
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-19 04:12:52 +08:00
|
|
|
def __init__(self, text):
|
|
|
|
self.regex = re.compile(text)
|
|
|
|
self.text = text
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-19 04:12:52 +08:00
|
|
|
def match(self, str):
|
|
|
|
return self.regex.match(str)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-19 04:12:52 +08:00
|
|
|
def __str__(self):
|
|
|
|
return "%s" % (self.text)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-19 04:12:52 +08:00
|
|
|
def __repr__(self):
|
|
|
|
return "re.compile(%s) -> %s" % (self.text, self.regex)
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-12-05 03:50:05 +08:00
|
|
|
def skip_if_callable(test, mycallable, reason):
|
|
|
|
if six.callable(mycallable):
|
|
|
|
if mycallable(test):
|
|
|
|
test.skipTest(reason)
|
|
|
|
return True
|
2015-09-19 04:12:52 +08:00
|
|
|
return False
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-19 04:12:52 +08:00
|
|
|
def skip_if_library_missing(test, target, library):
|
|
|
|
def find_library(target, library):
|
|
|
|
for module in target.modules:
|
|
|
|
filename = module.file.GetFilename()
|
|
|
|
if isinstance(library, str):
|
|
|
|
if library == filename:
|
|
|
|
return False
|
|
|
|
elif hasattr(library, 'match'):
|
|
|
|
if library.match(filename):
|
|
|
|
return False
|
|
|
|
return True
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-19 04:12:52 +08:00
|
|
|
def find_library_callable(test):
|
|
|
|
return find_library(target, library)
|
|
|
|
return skip_if_callable(
|
|
|
|
test,
|
|
|
|
find_library_callable,
|
|
|
|
"could not find library matching '%s' in target %s" %
|
|
|
|
(library,
|
|
|
|
target))
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-04-05 22:08:18 +08:00
|
|
|
|
2018-03-15 21:47:09 +08:00
|
|
|
def read_file_on_target(test, remote):
|
|
|
|
if lldb.remote_platform:
|
|
|
|
local = test.getBuildArtifact("file_from_target")
|
|
|
|
error = lldb.remote_platform.Get(lldb.SBFileSpec(remote, False),
|
|
|
|
lldb.SBFileSpec(local, True))
|
|
|
|
test.assertTrue(error.Success(), "Reading file {0} failed: {1}".format(remote, error))
|
|
|
|
else:
|
|
|
|
local = remote
|
|
|
|
with open(local, 'r') as f:
|
|
|
|
return f.read()
|
|
|
|
|
|
|
|
def read_file_from_process_wd(test, name):
|
|
|
|
path = append_to_process_working_directory(test, name)
|
|
|
|
return read_file_on_target(test, path)
|
|
|
|
|
2016-04-05 22:08:18 +08:00
|
|
|
def wait_for_file_on_target(testcase, file_path, max_attempts=6):
|
|
|
|
for i in range(max_attempts):
|
|
|
|
err, retcode, msg = testcase.run_platform_command("ls %s" % file_path)
|
|
|
|
if err.Success() and retcode == 0:
|
|
|
|
break
|
|
|
|
if i < max_attempts:
|
|
|
|
# Exponential backoff!
|
2016-04-09 02:06:11 +08:00
|
|
|
import time
|
2016-04-05 22:08:18 +08:00
|
|
|
time.sleep(pow(2, i) * 0.25)
|
|
|
|
else:
|
|
|
|
testcase.fail(
|
|
|
|
"File %s not found even after %d attempts." %
|
|
|
|
(file_path, max_attempts))
|
|
|
|
|
2018-03-15 21:47:09 +08:00
|
|
|
return read_file_on_target(testcase, file_path)
|
2020-07-25 09:36:18 +08:00
|
|
|
|
|
|
|
def packetlog_get_process_info(log):
|
|
|
|
"""parse a gdb-remote packet log file and extract the response to qProcessInfo"""
|
|
|
|
process_info = dict()
|
|
|
|
with open(log, "r") as logfile:
|
|
|
|
process_info_ostype = None
|
|
|
|
expect_process_info_response = False
|
|
|
|
for line in logfile:
|
|
|
|
if expect_process_info_response:
|
|
|
|
for pair in line.split(';'):
|
|
|
|
keyval = pair.split(':')
|
|
|
|
if len(keyval) == 2:
|
|
|
|
process_info[keyval[0]] = keyval[1]
|
|
|
|
break
|
|
|
|
if 'send packet: $qProcessInfo#' in line:
|
|
|
|
expect_process_info_response = True
|
|
|
|
return process_info
|
|
|
|
|
|
|
|
def packetlog_get_dylib_info(log):
|
[lldb] Make packetlog_get_dylib_info returns the last full response
In sanitized builds the last packet this function finds for the
TestMacCatalyst and TestPlatformSimulator tests is for the asan runtime.
```
< 69> send packet: $jGetLoadedDynamicLibrariesInfos:{"solib_addresses":[4296048640]}]#3a <
715> read packet: ${"images":[{"load_address":4296048640,"mod_date":0,"pathname":
"/Users/buildslave/jenkins/workspace/lldb-cmake-sanitized/host-compiler/lib/clang/12.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib",
"uuid":"8E38A2CD-753F-3E0F-8EB0-F4BD5788A5CA",
"min_version_os_name":"macosx","min_version_os_sdk":"10.9",
"mach_header":{"magic":4277009103,"cputype":16777223,"cpusubtype":3,"filetype":6,
"flags":43090053}],"segments":[{"name":"__TEXT","vmaddr":0,"vmsize":565248,"fileoff":0,
"filesize":565248,"maxprot":5}],{"name":"__DATA","vmaddr":565248,"vmsize":13152256,"fileoff":565248,
"filesize":20480,"maxprot":3}],{"name":"__LINKEDIT","vmaddr":13717504,"vmsize":438272,"fileoff":585728,
"filesize":435008,"maxprot":1}]]}]]}]#00
```
This just fetches the last package which has fetch_all_solibs and we know
it will contain the image of our test executable to get the tests running again.
2020-08-14 20:47:54 +08:00
|
|
|
"""parse a gdb-remote packet log file and extract the *last* complete
|
|
|
|
(=> fetch_all_solibs=true) response to jGetLoadedDynamicLibrariesInfos"""
|
2020-07-25 09:36:18 +08:00
|
|
|
import json
|
|
|
|
dylib_info = None
|
|
|
|
with open(log, "r") as logfile:
|
|
|
|
dylib_info = None
|
|
|
|
expect_dylib_info_response = False
|
|
|
|
for line in logfile:
|
|
|
|
if expect_dylib_info_response:
|
|
|
|
while line[0] != '$':
|
|
|
|
line = line[1:]
|
|
|
|
line = line[1:]
|
|
|
|
# Unescape '}'.
|
|
|
|
dylib_info = json.loads(line.replace('}]','}')[:-4])
|
|
|
|
expect_dylib_info_response = False
|
[lldb] Make packetlog_get_dylib_info returns the last full response
In sanitized builds the last packet this function finds for the
TestMacCatalyst and TestPlatformSimulator tests is for the asan runtime.
```
< 69> send packet: $jGetLoadedDynamicLibrariesInfos:{"solib_addresses":[4296048640]}]#3a <
715> read packet: ${"images":[{"load_address":4296048640,"mod_date":0,"pathname":
"/Users/buildslave/jenkins/workspace/lldb-cmake-sanitized/host-compiler/lib/clang/12.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib",
"uuid":"8E38A2CD-753F-3E0F-8EB0-F4BD5788A5CA",
"min_version_os_name":"macosx","min_version_os_sdk":"10.9",
"mach_header":{"magic":4277009103,"cputype":16777223,"cpusubtype":3,"filetype":6,
"flags":43090053}],"segments":[{"name":"__TEXT","vmaddr":0,"vmsize":565248,"fileoff":0,
"filesize":565248,"maxprot":5}],{"name":"__DATA","vmaddr":565248,"vmsize":13152256,"fileoff":565248,
"filesize":20480,"maxprot":3}],{"name":"__LINKEDIT","vmaddr":13717504,"vmsize":438272,"fileoff":585728,
"filesize":435008,"maxprot":1}]]}]]}]#00
```
This just fetches the last package which has fetch_all_solibs and we know
it will contain the image of our test executable to get the tests running again.
2020-08-14 20:47:54 +08:00
|
|
|
if 'send packet: $jGetLoadedDynamicLibrariesInfos:{"fetch_all_solibs":true}' in line:
|
2020-07-25 09:36:18 +08:00
|
|
|
expect_dylib_info_response = True
|
|
|
|
|
|
|
|
return dylib_info
|