2010-12-09 18:22:12 +00:00
|
|
|
"""
|
|
|
|
|
Test lldb core component: SourceManager.
|
|
|
|
|
|
|
|
|
|
Test cases:
|
2010-12-09 22:06:05 +00:00
|
|
|
|
2010-12-11 01:20:39 +00:00
|
|
|
o test_display_source_python:
|
|
|
|
|
Test display of source using the SBSourceManager API.
|
2010-12-09 22:06:05 +00:00
|
|
|
o test_modify_source_file_while_debugging:
|
|
|
|
|
Test the caching mechanism of the source manager.
|
2010-12-09 18:22:12 +00:00
|
|
|
"""
|
|
|
|
|
|
2015-10-23 17:04:29 +00:00
|
|
|
from __future__ import print_function
|
2015-11-03 19:20:39 +00:00
|
|
|
|
2010-12-09 18:38:52 +00:00
|
|
|
import lldb
|
2016-02-04 23:04:17 +00:00
|
|
|
from lldbsuite.test.decorators import *
|
2015-11-03 02:06:18 +00:00
|
|
|
from lldbsuite.test.lldbtest import *
|
2016-02-04 23:04:17 +00:00
|
|
|
from lldbsuite.test import lldbutil
|
2010-12-09 18:22:12 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
def ansi_underline_surround_regex(inner_regex_text):
|
|
|
|
|
# return re.compile(r"\[4m%s\[0m" % inner_regex_text)
|
|
|
|
|
return "4.+\033\\[4m%s\033\\[0m" % inner_regex_text
|
|
|
|
|
|
2018-08-02 00:30:15 +00:00
|
|
|
def ansi_color_surround_regex(inner_regex_text):
|
|
|
|
|
return "\033\\[3[0-7]m%s\033\\[0m" % inner_regex_text
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
|
2010-12-09 18:22:12 +00:00
|
|
|
class SourceManagerTestCase(TestBase):
|
|
|
|
|
|
2013-12-10 23:19:29 +00:00
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
2010-12-09 18:22:12 +00:00
|
|
|
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
NO_DEBUG_INFO_TESTCASE = True
|
|
|
|
|
|
2010-12-09 18:22:12 +00:00
|
|
|
def setUp(self):
|
|
|
|
|
# Call super's setUp().
|
|
|
|
|
TestBase.setUp(self)
|
|
|
|
|
# Find the line number to break inside main().
|
2018-03-21 15:29:32 +00:00
|
|
|
self.file = self.getBuildArtifact("main-copy.c")
|
|
|
|
|
self.line = line_number("main.c", '// Set break point at this line.')
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
|
|
|
|
|
def get_expected_stop_column_number(self):
|
|
|
|
|
"""Return the 1-based column number of the first non-whitespace
|
|
|
|
|
character in the breakpoint source line."""
|
2018-03-21 15:29:32 +00:00
|
|
|
stop_line = get_line(self.file, self.line)
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
# The number of spaces that must be skipped to get to the first non-
|
|
|
|
|
# whitespace character --- where we expect the debugger breakpoint
|
|
|
|
|
# column to be --- is equal to the number of characters that get
|
|
|
|
|
# stripped off the front when we lstrip it, plus one to specify
|
|
|
|
|
# the character column after the initial whitespace.
|
|
|
|
|
return len(stop_line) - len(stop_line.lstrip()) + 1
|
|
|
|
|
|
2018-08-02 00:30:15 +00:00
|
|
|
def do_display_source_python_api(self, use_color, needle_regex, highlight_source=False):
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2018-01-19 23:24:35 +00:00
|
|
|
exe = self.getBuildArtifact("a.out")
|
2010-12-11 01:20:39 +00:00
|
|
|
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
|
|
|
|
|
|
|
|
|
target = self.dbg.CreateTarget(exe)
|
2011-05-24 18:22:45 +00:00
|
|
|
self.assertTrue(target, VALID_TARGET)
|
2010-12-11 01:20:39 +00:00
|
|
|
|
|
|
|
|
# Launch the process, and do not stop at the entry point.
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
args = None
|
|
|
|
|
envp = None
|
2013-12-13 19:18:59 +00:00
|
|
|
process = target.LaunchSimple(
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
args, envp, self.get_process_working_directory())
|
|
|
|
|
self.assertIsNotNone(process)
|
2010-12-11 01:20:39 +00:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Exercise Python APIs to display source lines.
|
|
|
|
|
#
|
|
|
|
|
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
# Setup whether we should use ansi escape sequences, including color
|
|
|
|
|
# and styles such as underline.
|
|
|
|
|
self.dbg.SetUseColor(use_color)
|
2018-08-02 00:30:15 +00:00
|
|
|
# Disable syntax highlighting if needed.
|
|
|
|
|
|
|
|
|
|
self.runCmd("settings set highlight-source " + str(highlight_source).lower())
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
|
2018-03-21 15:29:32 +00:00
|
|
|
filespec = lldb.SBFileSpec(self.file, False)
|
2010-12-11 01:20:39 +00:00
|
|
|
source_mgr = self.dbg.GetSourceManager()
|
|
|
|
|
# Use a string stream as the destination.
|
|
|
|
|
stream = lldb.SBStream()
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
column = self.get_expected_stop_column_number()
|
|
|
|
|
context_before = 2
|
|
|
|
|
context_after = 2
|
|
|
|
|
current_line_prefix = "=>"
|
|
|
|
|
source_mgr.DisplaySourceLinesWithLineNumbersAndColumn(
|
|
|
|
|
filespec, self.line, column, context_before, context_after,
|
|
|
|
|
current_line_prefix, stream)
|
2010-12-11 01:20:39 +00:00
|
|
|
|
2011-03-30 22:28:50 +00:00
|
|
|
# 2
|
|
|
|
|
# 3 int main(int argc, char const *argv[]) {
|
|
|
|
|
# => 4 printf("Hello world.\n"); // Set break point at this line.
|
|
|
|
|
# 5 return 0;
|
|
|
|
|
# 6 }
|
2018-08-02 00:30:15 +00:00
|
|
|
self.expect(stream.GetData(), "Source code displayed correctly:\n" + stream.GetData(),
|
2010-12-11 01:20:39 +00:00
|
|
|
exe=False,
|
2020-02-24 15:34:58 -08:00
|
|
|
patterns=['=>', '%d.*Hello world' % self.line,
|
2018-08-02 00:30:15 +00:00
|
|
|
needle_regex])
|
2011-12-20 00:41:28 +00:00
|
|
|
|
|
|
|
|
# Boundary condition testings for SBStream(). LLDB should not crash!
|
2012-10-05 19:14:57 +00:00
|
|
|
stream.Print(None)
|
2011-12-20 00:41:28 +00:00
|
|
|
stream.RedirectToFile(None, True)
|
2010-12-11 01:20:39 +00:00
|
|
|
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
@add_test_categories(['pyapi'])
|
|
|
|
|
def test_display_source_python_dumb_terminal(self):
|
|
|
|
|
"""Test display of source using the SBSourceManager API, using a
|
|
|
|
|
dumb terminal and thus no color support (the default)."""
|
|
|
|
|
use_color = False
|
|
|
|
|
self.do_display_source_python_api(use_color, r"\s+\^")
|
|
|
|
|
|
|
|
|
|
@add_test_categories(['pyapi'])
|
|
|
|
|
def test_display_source_python_ansi_terminal(self):
|
|
|
|
|
"""Test display of source using the SBSourceManager API, using a
|
|
|
|
|
dumb terminal and thus no color support (the default)."""
|
|
|
|
|
use_color = True
|
2018-08-30 00:09:21 +00:00
|
|
|
underline_regex = ansi_underline_surround_regex(r"printf")
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
self.do_display_source_python_api(use_color, underline_regex)
|
|
|
|
|
|
2018-08-02 00:30:15 +00:00
|
|
|
@add_test_categories(['pyapi'])
|
|
|
|
|
def test_display_source_python_ansi_terminal_syntax_highlighting(self):
|
|
|
|
|
"""Test display of source using the SBSourceManager API and check for
|
|
|
|
|
the syntax highlighted output"""
|
|
|
|
|
use_color = True
|
|
|
|
|
syntax_highlighting = True;
|
|
|
|
|
|
|
|
|
|
# Just pick 'int' as something that should be colored.
|
|
|
|
|
color_regex = ansi_color_surround_regex("int")
|
|
|
|
|
self.do_display_source_python_api(use_color, color_regex, syntax_highlighting)
|
|
|
|
|
|
|
|
|
|
# Same for 'char'.
|
|
|
|
|
color_regex = ansi_color_surround_regex("char")
|
|
|
|
|
self.do_display_source_python_api(use_color, color_regex, syntax_highlighting)
|
|
|
|
|
|
|
|
|
|
# Test that we didn't color unrelated identifiers.
|
2018-08-30 00:09:21 +00:00
|
|
|
self.do_display_source_python_api(use_color, r" main\(", syntax_highlighting)
|
|
|
|
|
self.do_display_source_python_api(use_color, r"\);", syntax_highlighting)
|
2018-08-02 00:30:15 +00:00
|
|
|
|
2015-09-30 10:12:40 +00:00
|
|
|
def test_move_and_then_display_source(self):
|
2011-12-12 21:59:28 +00:00
|
|
|
"""Test that target.source-map settings work by moving main.c to hidden/main.c."""
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2018-01-19 23:24:35 +00:00
|
|
|
exe = self.getBuildArtifact("a.out")
|
2011-12-12 21:59:28 +00:00
|
|
|
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
|
|
|
|
|
|
|
|
|
# Move main.c to hidden/main.c.
|
2018-03-21 15:29:32 +00:00
|
|
|
hidden = self.getBuildArtifact("hidden")
|
|
|
|
|
lldbutil.mkdir_p(hidden)
|
|
|
|
|
main_c_hidden = os.path.join(hidden, "main-copy.c")
|
|
|
|
|
os.rename(self.file, main_c_hidden)
|
2016-01-25 19:13:35 +00:00
|
|
|
|
2011-12-12 21:59:28 +00:00
|
|
|
if self.TraceOn():
|
2014-07-22 16:19:29 +00:00
|
|
|
system([["ls"]])
|
|
|
|
|
system([["ls", "hidden"]])
|
2011-12-12 21:59:28 +00:00
|
|
|
|
2016-07-08 23:06:38 +00:00
|
|
|
# Set source remapping with invalid replace path and verify we get an
|
|
|
|
|
# error
|
|
|
|
|
self.expect(
|
|
|
|
|
"settings set target.source-map /a/b/c/d/e /q/r/s/t/u",
|
|
|
|
|
error=True,
|
|
|
|
|
substrs=['''error: the replacement path doesn't exist: "/q/r/s/t/u"'''])
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-02-21 09:05:27 +00:00
|
|
|
# 'make -C' has resolved current directory to its realpath form.
|
|
|
|
|
builddir_real = os.path.realpath(self.getBuildDir())
|
|
|
|
|
hidden_real = os.path.realpath(hidden)
|
2011-12-12 21:59:28 +00:00
|
|
|
# Set target.source-map settings.
|
|
|
|
|
self.runCmd("settings set target.source-map %s %s" %
|
2019-02-21 09:05:27 +00:00
|
|
|
(builddir_real, hidden_real))
|
2011-12-12 21:59:28 +00:00
|
|
|
# And verify that the settings work.
|
|
|
|
|
self.expect("settings show target.source-map",
|
2019-02-21 09:05:27 +00:00
|
|
|
substrs=[builddir_real, hidden_real])
|
2011-12-12 21:59:28 +00:00
|
|
|
|
|
|
|
|
# Display main() and verify that the source mapping has been kicked in.
|
2013-02-06 00:35:33 +00:00
|
|
|
self.expect("source list -n main", SOURCE_DISPLAYED_CORRECTLY,
|
2011-12-12 21:59:28 +00:00
|
|
|
substrs=['Hello world'])
|
|
|
|
|
|
2020-01-01 14:19:41 -08:00
|
|
|
@skipIf(oslist=["windows"], bugnumber="llvm.org/pr44431")
|
2015-09-30 10:12:40 +00:00
|
|
|
def test_modify_source_file_while_debugging(self):
|
2010-12-09 18:22:12 +00:00
|
|
|
"""Modify a source file while debugging the executable."""
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2018-01-19 23:24:35 +00:00
|
|
|
exe = self.getBuildArtifact("a.out")
|
2010-12-09 18:22:12 +00:00
|
|
|
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
|
|
|
|
|
2012-09-22 00:05:11 +00:00
|
|
|
lldbutil.run_break_set_by_file_and_line(
|
2018-03-21 15:29:32 +00:00
|
|
|
self, "main-copy.c", self.line, num_expected_locations=1, loc_exact=True)
|
2010-12-09 18:22:12 +00:00
|
|
|
|
2015-07-01 23:56:30 +00:00
|
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
2010-12-09 18:22:12 +00:00
|
|
|
|
|
|
|
|
# The stop reason of the thread should be breakpoint.
|
|
|
|
|
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
|
Centralized a lot of the status information for processes,
threads, and stack frame down in the lldb_private::Process,
lldb_private::Thread, lldb_private::StackFrameList and the
lldb_private::StackFrame classes. We had some command line
commands that had duplicate versions of the process status
output ("thread list" and "process status" for example).
Removed the "file" command and placed it where it should
have been: "target create". Made an alias for "file" to
"target create" so we stay compatible with GDB commands.
We can now have multple usable targets in lldb at the
same time. This is nice for comparing two runs of a program
or debugging more than one binary at the same time. The
new command is "target select <target-idx>" and also to see
a list of the current targets you can use the new "target list"
command. The flow in a debug session can be:
(lldb) target create /path/to/exe/a.out
(lldb) breakpoint set --name main
(lldb) run
... hit breakpoint
(lldb) target create /bin/ls
(lldb) run /tmp
Process 36001 exited with status = 0 (0x00000000)
(lldb) target list
Current targets:
target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
* target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) target select 0
Current targets:
* target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) bt
* thread #1: tid = 0x2d03, 0x0000000100000b9a a.out`main + 42 at main.c:16, stop reason = breakpoint 1.1
frame #0: 0x0000000100000b9a a.out`main + 42 at main.c:16
frame #1: 0x0000000100000b64 a.out`start + 52
Above we created a target for "a.out" and ran and hit a
breakpoint at "main". Then we created a new target for /bin/ls
and ran it. Then we listed the targest and selected our original
"a.out" program, so we showed two concurent debug sessions
going on at the same time.
llvm-svn: 129695
2011-04-18 08:33:37 +00:00
|
|
|
substrs=['stopped',
|
2018-03-21 15:29:32 +00:00
|
|
|
'main-copy.c:%d' % self.line,
|
2010-12-09 18:22:12 +00:00
|
|
|
'stop reason = breakpoint'])
|
|
|
|
|
|
|
|
|
|
# Display some source code.
|
2013-02-06 00:35:33 +00:00
|
|
|
self.expect(
|
2018-03-21 15:29:32 +00:00
|
|
|
"source list -f main-copy.c -l %d" %
|
2013-02-06 00:35:33 +00:00
|
|
|
self.line,
|
|
|
|
|
SOURCE_DISPLAYED_CORRECTLY,
|
2010-12-09 18:22:12 +00:00
|
|
|
substrs=['Hello world'])
|
|
|
|
|
|
2011-04-20 20:35:59 +00:00
|
|
|
# The '-b' option shows the line table locations from the debug information
|
|
|
|
|
# that indicates valid places to set source level breakpoints.
|
|
|
|
|
|
|
|
|
|
# The file to display is implicit in this case.
|
2013-02-06 00:35:33 +00:00
|
|
|
self.runCmd("source list -l %d -c 3 -b" % self.line)
|
2011-04-20 20:35:59 +00:00
|
|
|
output = self.res.GetOutput().splitlines()[0]
|
|
|
|
|
|
|
|
|
|
# If the breakpoint set command succeeded, we should expect a positive number
|
|
|
|
|
# of breakpoints for the current line, i.e., self.line.
|
|
|
|
|
import re
|
|
|
|
|
m = re.search('^\[(\d+)\].*// Set break point at this line.', output)
|
|
|
|
|
if not m:
|
|
|
|
|
self.fail("Fail to display source level breakpoints")
|
|
|
|
|
self.assertTrue(int(m.group(1)) > 0)
|
|
|
|
|
|
2010-12-09 18:22:12 +00:00
|
|
|
# Read the main.c file content.
|
2018-03-21 15:29:32 +00:00
|
|
|
with io.open(self.file, 'r', newline='\n') as f:
|
2010-12-09 18:22:12 +00:00
|
|
|
original_content = f.read()
|
2011-04-19 22:11:23 +00:00
|
|
|
if self.TraceOn():
|
2015-10-23 17:04:29 +00:00
|
|
|
print("original content:", original_content)
|
2010-12-09 18:22:12 +00:00
|
|
|
|
|
|
|
|
# Modify the in-memory copy of the original source code.
|
|
|
|
|
new_content = original_content.replace('Hello world', 'Hello lldb', 1)
|
|
|
|
|
|
|
|
|
|
# Modify the source code file.
|
2018-03-21 15:29:32 +00:00
|
|
|
with io.open(self.file, 'w', newline='\n') as f:
|
2011-03-04 01:35:22 +00:00
|
|
|
time.sleep(1)
|
2010-12-09 18:22:12 +00:00
|
|
|
f.write(new_content)
|
2011-04-19 22:11:23 +00:00
|
|
|
if self.TraceOn():
|
2015-10-23 17:04:29 +00:00
|
|
|
print("new content:", new_content)
|
|
|
|
|
print(
|
|
|
|
|
"os.path.getmtime() after writing new content:",
|
2018-03-21 15:29:32 +00:00
|
|
|
os.path.getmtime(self.file))
|
2010-12-09 18:22:12 +00:00
|
|
|
|
|
|
|
|
# Display the source code again. We should see the updated line.
|
2013-02-06 00:35:33 +00:00
|
|
|
self.expect(
|
2018-03-21 15:29:32 +00:00
|
|
|
"source list -f main-copy.c -l %d" %
|
2013-02-06 00:35:33 +00:00
|
|
|
self.line,
|
|
|
|
|
SOURCE_DISPLAYED_CORRECTLY,
|
2010-12-09 18:22:12 +00:00
|
|
|
substrs=['Hello lldb'])
|
2016-03-04 11:26:44 +00:00
|
|
|
|
2020-01-01 14:19:41 -08:00
|
|
|
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr44432")
|
2016-04-19 09:31:14 +00:00
|
|
|
def test_set_breakpoint_with_absolute_path(self):
|
2016-03-04 11:26:44 +00:00
|
|
|
self.build()
|
2018-03-21 15:29:32 +00:00
|
|
|
hidden = self.getBuildArtifact("hidden")
|
|
|
|
|
lldbutil.mkdir_p(hidden)
|
2019-02-21 09:05:27 +00:00
|
|
|
# 'make -C' has resolved current directory to its realpath form.
|
|
|
|
|
builddir_real = os.path.realpath(self.getBuildDir())
|
|
|
|
|
hidden_real = os.path.realpath(hidden)
|
2016-03-04 11:26:44 +00:00
|
|
|
self.runCmd("settings set target.source-map %s %s" %
|
2019-02-21 09:05:27 +00:00
|
|
|
(builddir_real, hidden_real))
|
2016-03-04 11:26:44 +00:00
|
|
|
|
2018-01-19 23:24:35 +00:00
|
|
|
exe = self.getBuildArtifact("a.out")
|
2019-02-21 09:05:27 +00:00
|
|
|
main = os.path.join(builddir_real, "hidden", "main-copy.c")
|
2016-03-04 11:26:44 +00:00
|
|
|
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
|
|
|
|
|
|
|
|
|
lldbutil.run_break_set_by_file_and_line(
|
|
|
|
|
self, main, self.line, num_expected_locations=1, loc_exact=False)
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-03-04 11:26:44 +00:00
|
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
|
|
|
|
|
|
|
|
|
# The stop reason of the thread should be breakpoint.
|
|
|
|
|
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
|
|
|
|
|
substrs=['stopped',
|
2018-03-21 15:29:32 +00:00
|
|
|
'main-copy.c:%d' % self.line,
|
2016-03-04 11:26:44 +00:00
|
|
|
'stop reason = breakpoint'])
|