Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get the expression parser to handle missing weak symbols.
MachO only for this patch. Differential Revision: https://reviews.llvm.org/D63914 <rdar://problem/51463642> llvm-svn: 364686
- Loading branch information
Showing
14 changed files
with
269 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
LEVEL = ../../make | ||
CFLAGS_EXTRAS += -std=c99 | ||
LD_FLAGS := -dynamiclib | ||
include $(LEVEL)/Makefile.rules | ||
|
||
all: a.out dylib missing | ||
|
||
dylib: dylib.o | ||
$(CC) $(LD_FLAGS) -o libdylib.dylib dylib.o | ||
|
||
missing: dylib2.o | ||
mkdir hidden | ||
$(CC) $(LD_FLAGS) -o hidden/libdylib.dylib dylib2.o | ||
|
||
a.out: main.o dylib missing | ||
$(CC) $(CFLAGS) -L. -ldylib main.o | ||
|
||
dylib.o: dylib.h $(SRCDIR)/dylib.c | ||
$(CC) -DHAS_THEM $(CFLAGS) -c $(SRCDIR)/dylib.c | ||
|
||
dylib2.o: dylib.h $(SRCDIR)/dylib.c | ||
$(CC) $(CFLAGS) -c $(SRCDIR)/dylib.c -o dylib2.o | ||
|
||
main.o: dylib.h $(SRCDIR)/main.c | ||
$(CC) $(CFLAGS) -c $(SRCDIR)/main.c -fmodules | ||
|
83 changes: 83 additions & 0 deletions
83
lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/TestWeakSymbols.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
""" | ||
Test that we can compile expressions referring to | ||
absent weak symbols from a dylib. | ||
""" | ||
|
||
from __future__ import print_function | ||
|
||
|
||
import os | ||
import time | ||
import re | ||
import lldb | ||
from lldbsuite.test import decorators | ||
import lldbsuite.test.lldbutil as lldbutil | ||
from lldbsuite.test.lldbtest import * | ||
|
||
|
||
class TestWeakSymbolsInExpressions(TestBase): | ||
|
||
mydir = TestBase.compute_mydir(__file__) | ||
|
||
NO_DEBUG_INFO_TESTCASE = True | ||
|
||
@decorators.skipUnlessDarwin | ||
def test_weak_symbol_in_expr(self): | ||
"""Tests that we can refer to weak symbols in expressions.""" | ||
self.build() | ||
self.main_source_file = lldb.SBFileSpec("main.c") | ||
self.do_test() | ||
|
||
def setUp(self): | ||
# Call super's setUp(). | ||
TestBase.setUp(self) | ||
|
||
def run_weak_var_check (self, weak_varname, present): | ||
# The expression will modify present_weak_int to signify which branch | ||
# was taken. Set it to so we don't get confused by a previous run. | ||
value = self.target.FindFirstGlobalVariable("present_weak_int") | ||
value.SetValueFromCString("0") | ||
if present: | ||
correct_value = 10 | ||
else: | ||
correct_value = 20 | ||
|
||
# Note, I'm adding the "; 10" at the end of the expression to work around | ||
# the bug that expressions with no result currently return False for Success()... | ||
expr = "if (&" + weak_varname + " != NULL) { present_weak_int = 10; } else { present_weak_int = 20;}; 10" | ||
result = self.frame.EvaluateExpression(expr) | ||
self.assertTrue(result.GetError().Success(), "absent_weak_int expr failed: %s"%(result.GetError().GetCString())) | ||
self.assertEqual(value.GetValueAsSigned(), correct_value, "Didn't change present_weak_int correctly.") | ||
|
||
def do_test(self): | ||
hidden_dir = os.path.join(self.getBuildDir(), "hidden") | ||
|
||
launch_info = lldb.SBLaunchInfo(None) | ||
launch_info.SetWorkingDirectory(self.getBuildDir()) | ||
# We have to point to the hidden directory to pick up the | ||
# version of the dylib without the weak symbols: | ||
env_expr = self.platformContext.shlib_environment_var + "=" + hidden_dir | ||
launch_info.SetEnvironmentEntries([env_expr], True) | ||
|
||
(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, | ||
"Set a breakpoint here", self.main_source_file, | ||
launch_info = launch_info) | ||
# First we have to import the Dylib module so we get the type info | ||
# for the weak symbol. We need to add the source dir to the module | ||
# search paths, and then run @import to introduce it into the expression | ||
# context: | ||
self.dbg.HandleCommand("settings set target.clang-module-search-paths " + self.getSourceDir()) | ||
|
||
self.frame = thread.frames[0] | ||
self.assertTrue(self.frame.IsValid(), "Got a good frame") | ||
options = lldb.SBExpressionOptions() | ||
options.SetLanguage(lldb.eLanguageTypeObjC) | ||
result = self.frame.EvaluateExpression("@import Dylib", options) | ||
|
||
# Now run an expression that references an absent weak symbol: | ||
self.run_weak_var_check("absent_weak_int", False) | ||
self.run_weak_var_check("absent_weak_function", False) | ||
|
||
# Make sure we can do the same thing with present weak symbols | ||
self.run_weak_var_check("present_weak_int", True) | ||
self.run_weak_var_check("present_weak_function", True) |
14 changes: 14 additions & 0 deletions
14
lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/dylib.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "dylib.h" | ||
|
||
int present_weak_int = 10; | ||
int present_weak_function() | ||
{ | ||
return present_weak_int; | ||
} | ||
|
||
#if defined HAS_THEM | ||
int absent_weak_int = 10; | ||
int absent_weak_function() { | ||
return absent_weak_int; | ||
} | ||
#endif |
8 changes: 8 additions & 0 deletions
8
lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/dylib.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
extern int absent_weak_int __attribute__((weak_import)); | ||
|
||
extern int present_weak_int __attribute__((weak_import)); | ||
|
||
extern int absent_weak_function() __attribute__((weak_import)); | ||
|
||
extern int present_weak_function() __attribute__((weak_import)); | ||
|
23 changes: 23 additions & 0 deletions
23
lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "dylib.h" | ||
#include <stdio.h> | ||
|
||
int | ||
doSomething() | ||
{ | ||
// Set a breakpoint here. | ||
if (&absent_weak_int != NULL) | ||
printf("In absent_weak_int: %d\n", absent_weak_int); | ||
if (absent_weak_function != NULL) | ||
printf("In absent_weak_func: %p\n", absent_weak_function); | ||
if (&present_weak_int != NULL) | ||
printf("In present_weak_int: %d\n", present_weak_int); | ||
if (present_weak_function != NULL) | ||
printf("In present_weak_func: %p\n", present_weak_function); | ||
|
||
} | ||
|
||
int | ||
main() | ||
{ | ||
return doSomething(); | ||
} |
3 changes: 3 additions & 0 deletions
3
lldb/packages/Python/lldbsuite/test/expression_command/weak_symbols/module.modulemap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Dylib { | ||
header "dylib.h" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.