Skip to content

Commit d55dabb

Browse files
committed
Merge remote-tracking branch 'origin/swift-4.0-branch' into stable
2 parents 573b356 + b6ac68d commit d55dabb

File tree

20 files changed

+456
-126
lines changed

20 files changed

+456
-126
lines changed

include/lldb/Symbol/SymbolContext.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,29 @@ class SymbolContext {
235235

236236
bool GetAddressRangeFromHereToEndLine(uint32_t end_line, AddressRange &range,
237237
Error &error);
238+
239+
//------------------------------------------------------------------
240+
/// Find the best global data symbol visible from this context.
241+
///
242+
/// Symbol priority is:
243+
/// - extern symbol in the current module if there is one
244+
/// - non-extern symbol in the current module if there is one
245+
/// - extern symbol in the target
246+
/// - non-extern symbol in the target
247+
/// It is an error if the highest-priority result is ambiguous.
248+
///
249+
/// @param[in] name
250+
/// The name of the symbol to search for.
251+
///
252+
/// @param[out] error
253+
/// An error that will be populated with a message if there was an
254+
/// ambiguous result. The error will not be populated if no result
255+
/// was found.
256+
///
257+
/// @return
258+
/// The symbol that was found, or \b nullptr if none was found.
259+
//------------------------------------------------------------------
260+
const Symbol *FindBestGlobalDataSymbol(const ConstString &name, Error &error);
238261

239262
void GetDescription(Stream *s, lldb::DescriptionLevel level,
240263
Target *target) const;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
LEVEL := ../../../make
2+
3+
LD_EXTRAS := -L. -l$(LIB_PREFIX)One -l$(LIB_PREFIX)Two
4+
C_SOURCES := main.c
5+
6+
main.o : CFLAGS_EXTRAS += -g -O0
7+
8+
include $(LEVEL)/Makefile.rules
9+
10+
.PHONY:
11+
a.out: lib_One lib_Two
12+
13+
lib_%:
14+
$(MAKE) -f $*.mk
15+
16+
clean::
17+
$(MAKE) -f One.mk clean
18+
$(MAKE) -f Two.mk clean
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
LEVEL := ../../../make
2+
3+
DYLIB_NAME := One
4+
DYLIB_C_SOURCES := One/One.c One/OneConstant.c
5+
DYLIB_ONLY := YES
6+
7+
include $(LEVEL)/Makefile.rules
8+
9+
CFLAGS_EXTRAS += -fPIC
10+
11+
One/OneConstant.o: One/OneConstant.c
12+
$(CC) $(CFLAGS_NO_DEBUG) -c $< -o $@
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "One.h"
2+
#include <stdio.h>
3+
4+
void one() {
5+
printf("One\n"); // break here
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ifndef ONE_H
2+
#define ONE_H
3+
void one();
4+
#endif
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int __attribute__ ((visibility("hidden"))) conflicting_symbol = 11111;
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
"""Test that conflicting symbols in different shared libraries work correctly"""
2+
3+
from __future__ import print_function
4+
5+
6+
import os
7+
import time
8+
import lldb
9+
from lldbsuite.test.decorators import *
10+
from lldbsuite.test.lldbtest import *
11+
from lldbsuite.test import lldbutil
12+
13+
14+
class TestConflictingSymbols(TestBase):
15+
16+
mydir = TestBase.compute_mydir(__file__)
17+
NO_DEBUG_INFO_TESTCASE = True
18+
19+
def test_conflicting_symbols(self):
20+
self.build()
21+
exe = os.path.join(os.getcwd(), "a.out")
22+
target = self.dbg.CreateTarget("a.out")
23+
self.assertTrue(target, VALID_TARGET)
24+
25+
# Register our shared libraries for remote targets so they get
26+
# automatically uploaded
27+
environment = self.registerSharedLibrariesWithTarget(
28+
target, ['One', 'Two'])
29+
30+
One_line = line_number('One/One.c', '// break here')
31+
Two_line = line_number('Two/Two.c', '// break here')
32+
main_line = line_number('main.c', '// break here')
33+
lldbutil.run_break_set_command(
34+
self, 'breakpoint set -f One.c -l %s' % (One_line))
35+
lldbutil.run_break_set_command(
36+
self, 'breakpoint set -f Two.c -l %s' % (Two_line))
37+
lldbutil.run_break_set_by_file_and_line(
38+
self, 'main.c', main_line, num_expected_locations=1, loc_exact=True)
39+
40+
process = target.LaunchSimple(
41+
None, environment, self.get_process_working_directory())
42+
self.assertTrue(process, PROCESS_IS_VALID)
43+
44+
# The stop reason of the thread should be breakpoint.
45+
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
46+
substrs=['stopped',
47+
'stop reason = breakpoint'])
48+
49+
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
50+
substrs=[' resolved, hit count = 1'])
51+
52+
# This should display correctly.
53+
self.expect(
54+
"expr (unsigned long long)conflicting_symbol",
55+
"Symbol from One should be found",
56+
substrs=[
57+
"11111"])
58+
59+
self.runCmd("continue", RUN_SUCCEEDED)
60+
61+
# The stop reason of the thread should be breakpoint.
62+
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
63+
substrs=['stopped',
64+
'stop reason = breakpoint'])
65+
66+
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
67+
substrs=[' resolved, hit count = 1'])
68+
69+
self.expect(
70+
"expr (unsigned long long)conflicting_symbol",
71+
"Symbol from Two should be found",
72+
substrs=[
73+
"22222"])
74+
75+
self.runCmd("continue", RUN_SUCCEEDED)
76+
77+
# The stop reason of the thread should be breakpoint.
78+
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
79+
substrs=['stopped',
80+
'stop reason = breakpoint'])
81+
82+
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
83+
substrs=[' resolved, hit count = 1'])
84+
85+
self.expect(
86+
"expr (unsigned long long)conflicting_symbol",
87+
"An error should be printed when symbols can't be ordered",
88+
error=True,
89+
substrs=[
90+
"Multiple internal symbols"])
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
LEVEL := ../../../make
2+
3+
DYLIB_NAME := Two
4+
DYLIB_C_SOURCES := Two/Two.c Two/TwoConstant.c
5+
DYLIB_ONLY := YES
6+
7+
include $(LEVEL)/Makefile.rules
8+
9+
CFLAGS_EXTRAS += -fPIC
10+
11+
Two/TwoConstant.o: Two/TwoConstant.c
12+
$(CC) $(CFLAGS_NO_DEBUG) -c $< -o $@
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "Two.h"
2+
#include <stdio.h>
3+
4+
void two() {
5+
printf("Two\n"); // break here
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ifndef TWO_H
2+
#define TWO_H
3+
void two();
4+
#endif
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int __attribute__ ((visibility("hidden"))) conflicting_symbol = 22222;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "One/One.h"
2+
#include "Two/Two.h"
3+
4+
#include <stdio.h>
5+
6+
int main() {
7+
one();
8+
two();
9+
printf("main\n"); // break here
10+
return(0);
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
LEVEL = ../../../make
2+
3+
OBJC_SOURCES := main.m
4+
5+
include $(LEVEL)/Makefile.rules
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
Test the ptr_refs tool on Darwin with Objective-C
3+
"""
4+
5+
from __future__ import print_function
6+
7+
import os
8+
import lldb
9+
from lldbsuite.test.decorators import *
10+
from lldbsuite.test.lldbtest import *
11+
from lldbsuite.test import lldbutil
12+
13+
14+
class TestPtrRefsObjC(TestBase):
15+
16+
mydir = TestBase.compute_mydir(__file__)
17+
18+
@skipUnlessDarwin
19+
def test_ptr_refs(self):
20+
"""Test the ptr_refs tool on Darwin with Objective-C"""
21+
self.build()
22+
exe_name = 'a.out'
23+
exe = os.path.join(os.getcwd(), exe_name)
24+
25+
target = self.dbg.CreateTarget(exe)
26+
self.assertTrue(target, VALID_TARGET)
27+
28+
main_file_spec = lldb.SBFileSpec('main.m')
29+
breakpoint = target.BreakpointCreateBySourceRegex(
30+
'break', main_file_spec)
31+
self.assertTrue(breakpoint and
32+
breakpoint.GetNumLocations() == 1,
33+
VALID_BREAKPOINT)
34+
35+
process = target.LaunchSimple(
36+
None, None, self.get_process_working_directory())
37+
self.assertTrue(process, PROCESS_IS_VALID)
38+
39+
# Frame #0 should be on self.line1 and the break condition should hold.
40+
thread = lldbutil.get_stopped_thread(
41+
process, lldb.eStopReasonBreakpoint)
42+
self.assertTrue(
43+
thread.IsValid(),
44+
"There should be a thread stopped due to breakpoint condition")
45+
46+
frame = thread.GetFrameAtIndex(0)
47+
48+
self.dbg.HandleCommand("script import lldb.macosx.heap")
49+
self.expect("ptr_refs self", substrs=["malloc", "stack"])
50+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===-- main.c --------------------------------------------------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#import <Foundation/Foundation.h>
11+
12+
@interface MyClass : NSObject {
13+
};
14+
-(void)test;
15+
@end
16+
17+
@implementation MyClass
18+
-(void)test {
19+
printf("%p\n", self); // break here
20+
}
21+
@end
22+
23+
@interface MyOwner : NSObject {
24+
@public id ownedThing; // should be id, to test <rdar://problem/31363513>
25+
};
26+
@end
27+
28+
@implementation MyOwner
29+
@end
30+
31+
int main (int argc, char const *argv[]) {
32+
@autoreleasepool {
33+
MyOwner *owner = [[MyOwner alloc] init];
34+
owner->ownedThing = [[MyClass alloc] init];
35+
[(MyClass*)owner->ownedThing test];
36+
}
37+
return 0;
38+
}
39+

packages/Python/lldbsuite/test/lldbtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,7 @@ def registerSharedLibrariesWithTarget(self, target, shlibs):
19311931
# "libFoo.dylib" or "libFoo.so", or "Foo.so" for "Foo.so" or "libFoo.so", or just a
19321932
# basename like "libFoo.so". So figure out which one it is and resolve the local copy
19331933
# of the shared library accordingly
1934-
if os.path.exists(name):
1934+
if os.path.isfile(name):
19351935
local_shlib_path = name # name is the full path to the local shared library
19361936
else:
19371937
# Check relative names

0 commit comments

Comments
 (0)