Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@@ -0,0 +1,112 @@
"""
Test some lldb command abbreviations and aliases for proper resolution.
"""
from __future__ import print_function
import os
import time
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class AbbreviationsTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
@no_debug_info_test
def test_command_abbreviations_and_aliases(self):
command_interpreter = self.dbg.GetCommandInterpreter()
self.assertTrue(command_interpreter, VALID_COMMAND_INTERPRETER)
result = lldb.SBCommandReturnObject()
# Check that abbreviations are expanded to the full command.
command_interpreter.ResolveCommand("ap script", result)
self.assertTrue(result.Succeeded())
self.assertEqual("apropos script", result.GetOutput())
command_interpreter.ResolveCommand("h", result)
self.assertTrue(result.Succeeded())
self.assertEqual("help", result.GetOutput())
# Check resolution of abbreviations for multi-word commands.
command_interpreter.ResolveCommand("lo li", result)
self.assertTrue(result.Succeeded())
self.assertEqual("log list", result.GetOutput())
command_interpreter.ResolveCommand("br s", result)
self.assertTrue(result.Succeeded())
self.assertEqual("breakpoint set", result.GetOutput())
# Try an ambiguous abbreviation.
# "pl" could be "platform" or "plugin".
command_interpreter.ResolveCommand("pl", result)
self.assertFalse(result.Succeeded())
self.assertTrue(result.GetError().startswith("Ambiguous command"))
# Make sure an unabbreviated command is not mangled.
command_interpreter.ResolveCommand(
"breakpoint set --name main --line 123", result)
self.assertTrue(result.Succeeded())
self.assertEqual(
"breakpoint set --name main --line 123",
result.GetOutput())
# Create some aliases.
self.runCmd("com a alias com al")
self.runCmd("alias gurp help")
# Check that an alias is replaced with the actual command
command_interpreter.ResolveCommand("gurp target create", result)
self.assertTrue(result.Succeeded())
self.assertEqual("help target create", result.GetOutput())
# Delete the alias and make sure it no longer has an effect.
self.runCmd("com u gurp")
command_interpreter.ResolveCommand("gurp", result)
self.assertFalse(result.Succeeded())
# Check aliases with text replacement.
self.runCmd("alias pltty process launch -s -o %1 -e %1")
command_interpreter.ResolveCommand("pltty /dev/tty0", result)
self.assertTrue(result.Succeeded())
self.assertEqual(
"process launch -s -o /dev/tty0 -e /dev/tty0",
result.GetOutput())
self.runCmd("alias xyzzy breakpoint set -n %1 -l %2")
command_interpreter.ResolveCommand("xyzzy main 123", result)
self.assertTrue(result.Succeeded())
self.assertEqual(
"breakpoint set -n main -l 123",
result.GetOutput().strip())
# And again, without enough parameters.
command_interpreter.ResolveCommand("xyzzy main", result)
self.assertFalse(result.Succeeded())
# Check a command that wants the raw input.
command_interpreter.ResolveCommand(
r'''sc print("\n\n\tHello!\n")''', result)
self.assertTrue(result.Succeeded())
self.assertEqual(
r'''script print("\n\n\tHello!\n")''',
result.GetOutput())
# Prompt changing stuff should be tested, but this doesn't seem like the
# right test to do it in. It has nothing to do with aliases or abbreviations.
#self.runCmd("com sou ./change_prompt.lldb")
# self.expect("settings show prompt",
# startstr = 'prompt (string) = "[with-three-trailing-spaces] "')
#self.runCmd("settings clear prompt")
# self.expect("settings show prompt",
# startstr = 'prompt (string) = "(lldb) "')
#self.runCmd("se se prompt 'Sycamore> '")
# self.expect("se sh prompt",
# startstr = 'prompt (string) = "Sycamore> "')
#self.runCmd("se cl prompt")
# self.expect("set sh prompt",
# startstr = 'prompt (string) = "(lldb) "')

View File

@@ -0,0 +1,41 @@
"""
Test some lldb command abbreviations to make sure the common short spellings of
many commands remain available even after we add/delete commands in the future.
"""
from __future__ import print_function
import os
import time
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class CommonShortSpellingsTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
@no_debug_info_test
def test_abbrevs2(self):
command_interpreter = self.dbg.GetCommandInterpreter()
self.assertTrue(command_interpreter, VALID_COMMAND_INTERPRETER)
result = lldb.SBCommandReturnObject()
abbrevs = [
('br s', 'breakpoint set'),
('disp', '_regexp-display'), # a.k.a., 'display'
('di', 'disassemble'),
('dis', 'disassemble'),
('ta st a', 'target stop-hook add'),
('fr v', 'frame variable'),
('f 1', 'frame select 1'),
('ta st li', 'target stop-hook list'),
]
for (short_val, long_val) in abbrevs:
command_interpreter.ResolveCommand(short_val, result)
self.assertTrue(result.Succeeded())
self.assertEqual(long_val, result.GetOutput())

View File

@@ -0,0 +1,5 @@
LEVEL = ../../make
CXX_SOURCES := main.cpp
include $(LEVEL)/Makefile.rules

View File

@@ -0,0 +1,46 @@
"""
Test that apropos env doesn't crash trying to touch the process plugin commmand
"""
from __future__ import print_function
import os
import time
import re
import lldb
from lldbsuite.test.lldbtest import *
import lldbsuite.test.lldbutil as lldbutil
class AproposWithProcessTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break inside main().
self.line = line_number('main.cpp', '// break here')
def test_apropos_with_process(self):
"""Test that apropos env doesn't crash trying to touch the process plugin commmand."""
self.build()
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Break in main() aftre the variables are assigned values.
lldbutil.run_break_set_by_file_and_line(
self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
self.runCmd("run", RUN_SUCCEEDED)
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped', 'stop reason = breakpoint'])
# The breakpoint should have a hit count of 1.
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
substrs=[' resolved, hit count = 1'])
self.runCmd('apropos env')

View File

@@ -0,0 +1,15 @@
//===-- main.cpp ------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <stdio.h>
int main (int argc, char const *argv[])
{
return 0; // break here
}

View File

@@ -0,0 +1,9 @@
LEVEL = ../../make
C_SOURCES := main.c
MAKE_DSYM := NO
ARCHIVE_NAME := libfoo.a
ARCHIVE_C_SOURCES := a.c b.c
include $(LEVEL)/Makefile.rules

View File

@@ -0,0 +1,62 @@
a.out file refers to libfoo.a for a.o and b.o, which is what we want to accomplish for
this test case.
[16:17:44] johnny:/Volumes/data/lldb/svn/latest/test/functionalities/archives $ dsymutil -s a.out
----------------------------------------------------------------------
Symbol table for: 'a.out' (x86_64)
----------------------------------------------------------------------
Index n_strx n_type n_sect n_desc n_value
======== -------- ------------------ ------ ------ ----------------
[ 0] 00000002 64 (N_SO ) 00 0000 0000000000000000 '/Volumes/data/lldb/svn/latest/test/functionalities/archives/'
[ 1] 0000003f 64 (N_SO ) 00 0000 0000000000000000 'main.c'
[ 2] 00000046 66 (N_OSO ) 03 0001 000000004f0f780c '/Volumes/data/lldb/svn/latest/test/functionalities/archives/main.o'
[ 3] 00000001 2e (N_BNSYM ) 01 0000 0000000100000d70
[ 4] 00000089 24 (N_FUN ) 01 0000 0000000100000d70 '_main'
[ 5] 00000001 24 (N_FUN ) 00 0000 000000000000005d
[ 6] 00000001 4e (N_ENSYM ) 01 0000 000000000000005d
[ 7] 00000001 64 (N_SO ) 01 0000 0000000000000000
[ 8] 00000002 64 (N_SO ) 00 0000 0000000000000000 '/Volumes/data/lldb/svn/latest/test/functionalities/archives/'
[ 9] 0000008f 64 (N_SO ) 00 0000 0000000000000000 'a.c'
[ 10] 00000093 66 (N_OSO ) 03 0001 000000004f0f780c '/Volumes/data/lldb/svn/latest/test/functionalities/archives/libfoo.a(a.o)'
[ 11] 00000001 2e (N_BNSYM ) 01 0000 0000000100000dd0
[ 12] 000000dd 24 (N_FUN ) 01 0000 0000000100000dd0 '_a'
[ 13] 00000001 24 (N_FUN ) 00 0000 0000000000000020
[ 14] 00000001 4e (N_ENSYM ) 01 0000 0000000000000020
[ 15] 00000001 2e (N_BNSYM ) 01 0000 0000000100000df0
[ 16] 000000e0 24 (N_FUN ) 01 0000 0000000100000df0 '_aa'
[ 17] 00000001 24 (N_FUN ) 00 0000 0000000000000018
[ 18] 00000001 4e (N_ENSYM ) 01 0000 0000000000000018
[ 19] 000000e4 20 (N_GSYM ) 00 0000 0000000000000000 '___a_global'
[ 20] 00000001 64 (N_SO ) 01 0000 0000000000000000
[ 21] 00000002 64 (N_SO ) 00 0000 0000000000000000 '/Volumes/data/lldb/svn/latest/test/functionalities/archives/'
[ 22] 000000f0 64 (N_SO ) 00 0000 0000000000000000 'b.c'
[ 23] 000000f4 66 (N_OSO ) 03 0001 000000004f0f780c '/Volumes/data/lldb/svn/latest/test/functionalities/archives/libfoo.a(b.o)'
[ 24] 00000001 2e (N_BNSYM ) 01 0000 0000000100000e10
[ 25] 0000013e 24 (N_FUN ) 01 0000 0000000100000e10 '_b'
[ 26] 00000001 24 (N_FUN ) 00 0000 0000000000000020
[ 27] 00000001 4e (N_ENSYM ) 01 0000 0000000000000020
[ 28] 00000001 2e (N_BNSYM ) 01 0000 0000000100000e30
[ 29] 00000141 24 (N_FUN ) 01 0000 0000000100000e30 '_bb'
[ 30] 00000001 24 (N_FUN ) 00 0000 0000000000000018
[ 31] 00000001 4e (N_ENSYM ) 01 0000 0000000000000018
[ 32] 00000145 26 (N_STSYM ) 0a 0000 000000010000104c '___b_global'
[ 33] 00000001 64 (N_SO ) 01 0000 0000000000000000
[ 34] 00000151 0e ( SECT ) 07 0000 0000000100001000 '_pvars'
[ 35] 00000158 0e ( SECT ) 0a 0000 000000010000104c '___b_global'
[ 36] 00000164 0f ( SECT EXT) 0b 0000 0000000100001050 '_NXArgc'
[ 37] 0000016c 0f ( SECT EXT) 0b 0000 0000000100001058 '_NXArgv'
[ 38] 00000174 0f ( SECT EXT) 0a 0000 0000000100001048 '___a_global'
[ 39] 00000180 0f ( SECT EXT) 0b 0000 0000000100001068 '___progname'
[ 40] 0000018c 03 ( ABS EXT) 01 0010 0000000100000000 '__mh_execute_header'
[ 41] 000001a0 0f ( SECT EXT) 01 0000 0000000100000dd0 '_a'
[ 42] 000001a3 0f ( SECT EXT) 01 0000 0000000100000df0 '_aa'
[ 43] 000001a7 0f ( SECT EXT) 01 0000 0000000100000e10 '_b'
[ 44] 000001aa 0f ( SECT EXT) 01 0000 0000000100000e30 '_bb'
[ 45] 000001ae 0f ( SECT EXT) 0b 0000 0000000100001060 '_environ'
[ 46] 000001b7 0f ( SECT EXT) 01 0000 0000000100000d70 '_main'
[ 47] 000001bd 0f ( SECT EXT) 01 0000 0000000100000d30 'start'
[ 48] 000001c3 01 ( UNDF EXT) 00 0100 0000000000000000 '_exit'
[ 49] 000001c9 01 ( UNDF EXT) 00 0100 0000000000000000 '_printf'
[ 50] 000001d1 01 ( UNDF EXT) 00 0100 0000000000000000 'dyld_stub_binder'

View File

@@ -0,0 +1,70 @@
"""Test breaking inside functions defined within a BSD archive file libfoo.a."""
from __future__ import print_function
import os
import time
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class BSDArchivesTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number in a(int) to break at.
self.line = line_number(
'a.c', '// Set file and line breakpoint inside a().')
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr24527. Makefile.rules doesn't know how to build static libs on Windows")
@expectedFailureAll(
oslist=["linux"],
archs=[
"arm",
"aarch64"],
bugnumber="llvm.org/pr27795")
def test(self):
"""Break inside a() and b() defined within libfoo.a."""
self.build()
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Break inside a() by file and line first.
lldbutil.run_break_set_by_file_and_line(
self, "a.c", self.line, num_expected_locations=1, loc_exact=True)
self.runCmd("run", RUN_SUCCEEDED)
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped',
'stop reason = breakpoint'])
# Break at a(int) first.
self.expect("frame variable", VARIABLES_DISPLAYED_CORRECTLY,
substrs=['(int) arg = 1'])
self.expect("frame variable __a_global", VARIABLES_DISPLAYED_CORRECTLY,
substrs=['(int) __a_global = 1'])
# Set breakpoint for b() next.
lldbutil.run_break_set_by_symbol(
self, "b", num_expected_locations=1, sym_exact=True)
# Continue the program, we should break at b(int) next.
self.runCmd("continue")
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped',
'stop reason = breakpoint'])
self.expect("frame variable", VARIABLES_DISPLAYED_CORRECTLY,
substrs=['(int) arg = 2'])
self.expect("frame variable __b_global", VARIABLES_DISPLAYED_CORRECTLY,
substrs=['(int) __b_global = 2'])

View File

@@ -0,0 +1,19 @@
//===-- a.c -----------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int __a_global = 1;
int a(int arg) {
int result = arg + __a_global;
return result; // Set file and line breakpoint inside a().
}
int aa(int arg1) {
int result1 = arg1 - __a_global;
return result1;
}

View File

@@ -0,0 +1,19 @@
//===-- b.c -----------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
static int __b_global = 2;
int b(int arg) {
int result = arg + __b_global;
return result;
}
int bb(int arg1) {
int result2 = arg1 - __b_global;
return result2;
}

View File

@@ -0,0 +1,17 @@
//===-- main.c --------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <stdio.h>
extern int a(int);
extern int b(int);
int main (int argc, char const *argv[])
{
printf ("a(1) returns %d\n", a(1));
printf ("b(2) returns %d\n", b(2));
}

View File

@@ -0,0 +1,6 @@
LEVEL = ../../make
C_SOURCES := main.c
CFLAGS_EXTRAS := -fsanitize=address -g
include $(LEVEL)/Makefile.rules

View File

@@ -0,0 +1,134 @@
"""
Test that ASan memory history provider returns correct stack traces
"""
from __future__ import print_function
import os
import time
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbplatform
from lldbsuite.test import lldbutil
class AsanTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
@expectedFailureAll(
oslist=["linux"],
bugnumber="non-core functionality, need to reenable and fix later (DES 2014.11.07)")
@skipIfFreeBSD # llvm.org/pr21136 runtimes not yet available by default
@skipIfRemote
@skipUnlessAddressSanitizer
def test(self):
self.build()
self.asan_tests()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
self.line_malloc = line_number('main.c', '// malloc line')
self.line_malloc2 = line_number('main.c', '// malloc2 line')
self.line_free = line_number('main.c', '// free line')
self.line_breakpoint = line_number('main.c', '// break line')
def asan_tests(self):
exe = os.path.join(os.getcwd(), "a.out")
self.expect(
"file " + exe,
patterns=["Current executable set to .*a.out"])
self.runCmd("breakpoint set -f main.c -l %d" % self.line_breakpoint)
# "memory history" command should not work without a process
self.expect("memory history 0",
error=True,
substrs=["invalid process"])
self.runCmd("run")
stop_reason = self.dbg.GetSelectedTarget().process.GetSelectedThread().GetStopReason()
if stop_reason == lldb.eStopReasonExec:
# On OS X 10.10 and older, we need to re-exec to enable
# interceptors.
self.runCmd("continue")
# the stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped', 'stop reason = breakpoint'])
# test that the ASan dylib is present
self.expect(
"image lookup -n __asan_describe_address",
"__asan_describe_address should be present",
substrs=['1 match found'])
# test the 'memory history' command
self.expect(
"memory history 'pointer'",
substrs=[
'Memory allocated by Thread',
'a.out`f1',
'main.c:%d' %
self.line_malloc,
'Memory deallocated by Thread',
'a.out`f2',
'main.c:%d' %
self.line_free])
# do the same using SB API
process = self.dbg.GetSelectedTarget().process
val = process.GetSelectedThread().GetSelectedFrame().EvaluateExpression("pointer")
addr = val.GetValueAsUnsigned()
threads = process.GetHistoryThreads(addr)
self.assertEqual(threads.GetSize(), 2)
history_thread = threads.GetThreadAtIndex(0)
self.assertTrue(history_thread.num_frames >= 2)
self.assertEqual(history_thread.frames[1].GetLineEntry(
).GetFileSpec().GetFilename(), "main.c")
self.assertEqual(
history_thread.frames[1].GetLineEntry().GetLine(),
self.line_free)
history_thread = threads.GetThreadAtIndex(1)
self.assertTrue(history_thread.num_frames >= 2)
self.assertEqual(history_thread.frames[1].GetLineEntry(
).GetFileSpec().GetFilename(), "main.c")
self.assertEqual(
history_thread.frames[1].GetLineEntry().GetLine(),
self.line_malloc)
# let's free the container (SBThreadCollection) and see if the
# SBThreads still live
threads = None
self.assertTrue(history_thread.num_frames >= 2)
self.assertEqual(history_thread.frames[1].GetLineEntry(
).GetFileSpec().GetFilename(), "main.c")
self.assertEqual(
history_thread.frames[1].GetLineEntry().GetLine(),
self.line_malloc)
# ASan will break when a report occurs and we'll try the API then
self.runCmd("continue")
self.expect(
"thread list",
"Process should be stopped due to ASan report",
substrs=[
'stopped',
'stop reason = Use of deallocated memory'])
# make sure the 'memory history' command still works even when we're
# generating a report now
self.expect(
"memory history 'another_pointer'",
substrs=[
'Memory allocated by Thread',
'a.out`f1',
'main.c:%d' %
self.line_malloc2])

View File

@@ -0,0 +1,94 @@
"""
Test the AddressSanitizer runtime support for report breakpoint and data extraction.
"""
from __future__ import print_function
import os
import time
import json
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class AsanTestReportDataCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
@expectedFailureAll(
oslist=["linux"],
bugnumber="non-core functionality, need to reenable and fix later (DES 2014.11.07)")
@skipIfFreeBSD # llvm.org/pr21136 runtimes not yet available by default
@skipIfRemote
@skipUnlessAddressSanitizer
@expectedFailureAll(archs=['i386'], bugnumber="rdar://28658860")
def test(self):
self.build()
self.asan_tests()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
self.line_malloc = line_number('main.c', '// malloc line')
self.line_malloc2 = line_number('main.c', '// malloc2 line')
self.line_free = line_number('main.c', '// free line')
self.line_breakpoint = line_number('main.c', '// break line')
self.line_crash = line_number('main.c', '// BOOM line')
def asan_tests(self):
exe = os.path.join(os.getcwd(), "a.out")
self.expect(
"file " + exe,
patterns=["Current executable set to .*a.out"])
self.runCmd("run")
stop_reason = self.dbg.GetSelectedTarget().process.GetSelectedThread().GetStopReason()
if stop_reason == lldb.eStopReasonExec:
# On OS X 10.10 and older, we need to re-exec to enable
# interceptors.
self.runCmd("continue")
self.expect(
"thread list",
"Process should be stopped due to ASan report",
substrs=[
'stopped',
'stop reason = Use of deallocated memory'])
self.assertEqual(
self.dbg.GetSelectedTarget().process.GetSelectedThread().GetStopReason(),
lldb.eStopReasonInstrumentation)
self.expect("bt", "The backtrace should show the crashing line",
substrs=['main.c:%d' % self.line_crash])
self.expect(
"thread info -s",
"The extended stop info should contain the ASan provided fields",
substrs=[
"access_size",
"access_type",
"address",
"pc",
"description",
"heap-use-after-free"])
output_lines = self.res.GetOutput().split('\n')
json_line = '\n'.join(output_lines[2:])
data = json.loads(json_line)
self.assertEqual(data["description"], "heap-use-after-free")
self.assertEqual(data["instrumentation_class"], "AddressSanitizer")
self.assertEqual(data["stop_type"], "fatal_error")
# now let's try the SB API
process = self.dbg.GetSelectedTarget().process
thread = process.GetSelectedThread()
s = lldb.SBStream()
self.assertTrue(thread.GetStopReasonExtendedInfoAsJSON(s))
s = s.GetData()
data2 = json.loads(s)
self.assertEqual(data, data2)

View File

@@ -0,0 +1,34 @@
//===-- main.c --------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <stdio.h>
#include <stdlib.h>
char *pointer;
char *another_pointer;
void f1() {
pointer = malloc(10); // malloc line
another_pointer = malloc(20); // malloc2 line
}
void f2() {
free(pointer); // free line
}
int main (int argc, char const *argv[])
{
f1();
f2();
printf("Hello world!\n"); // break line
pointer[0] = 'A'; // BOOM line
return 0;
}

View File

@@ -0,0 +1,7 @@
LEVEL = ../../make
CXX_SOURCES := main.cpp
ENABLE_THREADS := YES
EXE := AttachResume
include $(LEVEL)/Makefile.rules

View File

@@ -0,0 +1,94 @@
"""
Test process attach/resume.
"""
from __future__ import print_function
import os
import time
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
exe_name = "AttachResume" # Must match Makefile
class AttachResumeTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
@skipIfRemote
@expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr19310')
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24778")
def test_attach_continue_interrupt_detach(self):
"""Test attach/continue/interrupt/detach"""
self.build()
self.process_attach_continue_interrupt_detach()
def process_attach_continue_interrupt_detach(self):
"""Test attach/continue/interrupt/detach"""
exe = os.path.join(os.getcwd(), exe_name)
popen = self.spawnSubprocess(exe)
self.addTearDownHook(self.cleanupSubprocesses)
self.runCmd("process attach -p " + str(popen.pid))
self.setAsync(True)
listener = self.dbg.GetListener()
process = self.dbg.GetSelectedTarget().GetProcess()
self.runCmd("c")
lldbutil.expect_state_changes(
self, listener, process, [
lldb.eStateRunning])
self.runCmd("process interrupt")
lldbutil.expect_state_changes(
self, listener, process, [
lldb.eStateStopped])
# be sure to continue/interrupt/continue (r204504)
self.runCmd("c")
lldbutil.expect_state_changes(
self, listener, process, [
lldb.eStateRunning])
self.runCmd("process interrupt")
lldbutil.expect_state_changes(
self, listener, process, [
lldb.eStateStopped])
# Second interrupt should have no effect.
self.expect(
"process interrupt",
patterns=["Process is not running"],
error=True)
# check that this breakpoint is auto-cleared on detach (r204752)
self.runCmd("br set -f main.cpp -l %u" %
(line_number('main.cpp', '// Set breakpoint here')))
self.runCmd("c")
lldbutil.expect_state_changes(
self, listener, process, [
lldb.eStateRunning, lldb.eStateStopped])
self.expect('br list', 'Breakpoint not hit',
substrs=['hit count = 1'])
# Make sure the breakpoint is not hit again.
self.expect("expr debugger_flag = false", substrs=[" = false"])
self.runCmd("c")
lldbutil.expect_state_changes(
self, listener, process, [
lldb.eStateRunning])
# make sure to detach while in running state (r204759)
self.runCmd("detach")
lldbutil.expect_state_changes(
self, listener, process, [
lldb.eStateDetached])

View File

@@ -0,0 +1,35 @@
#include <stdio.h>
#include <fcntl.h>
#include <chrono>
#include <thread>
volatile bool debugger_flag = true; // The debugger will flip this to false
void *start(void *data)
{
int i;
size_t idx = (size_t)data;
for (i=0; i<30; i++)
{
if ( idx == 0 && debugger_flag)
std::this_thread::sleep_for(std::chrono::microseconds(1)); // Set breakpoint here
std::this_thread::sleep_for(std::chrono::seconds(1));
}
return 0;
}
int main(int argc, char const *argv[])
{
lldb_enable_attach();
static const size_t nthreads = 16;
std::thread threads[nthreads];
size_t i;
for (i=0; i<nthreads; i++)
threads[i] = std::move(std::thread(start, (void*)i));
for (i=0; i<nthreads; i++)
threads[i].join();
}

Some files were not shown because too many files have changed in this diff Show More