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

0 commit comments

Comments
 (0)