Skip to content

Commit bd31d69

Browse files
committed
Apply tensorflow lldb changes to the lldb branch.
1 parent a1cb063 commit bd31d69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2207
-267
lines changed

lldb/cmake/modules/AddLLDB.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
# SWIFT_ENABLE_TENSORFLOW
2+
function(add_tensorflow_compiler_flags target)
3+
# TODO: Handle Mac. Not urgent because lldb is built with Xcode by default on Mac.
4+
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
5+
# If INSTALL_PATH is already defined, append a path separater ":".
6+
get_property(old_rpath TARGET "${target}" PROPERTY INSTALL_RPATH)
7+
if(old_rpath)
8+
set_property(TARGET "${target}" APPEND_STRING PROPERTY INSTALL_RPATH ":")
9+
endif()
10+
# FIXME: This is a hack: adding rpaths with many `..` that jump across
11+
# frameworks is bad practice. It would be cleaner/more robust to copy
12+
# the TensorFlow libraries to the lldb build subdirectory.
13+
set(swift_lib_dir "../../swift-${HOST_VARIANT}-${HOST_VARIANT_ARCH}")
14+
set(rpath_lldb_binary "${swift_lib_dir}/lib/swift/${HOST_VARIANT}")
15+
set(rpath_toolchain_lldb_binary "../lib/swift/${HOST_VARIANT}")
16+
set(rpath_lldb_python_lib "../../../${rpath_lldb_binary}")
17+
set(rpath_toolchain_lldb_python_lib "../../../${rpath_lldb_binary}")
18+
set_property(TARGET "${target}" APPEND_STRING PROPERTY
19+
INSTALL_RPATH "$ORIGIN/${rpath_lldb_binary}:$ORIGIN/${rpath_toolchain_lldb_binary}:$ORIGIN/${rpath_lldb_python_lib}:$ORIGIN/${rpath_toolchain_lldb_python_lib}")
20+
set_property(TARGET "${target}" APPEND_STRING PROPERTY
21+
LINK_FLAGS " -L${LLDB_PATH_TO_SWIFT_BUILD}/lib/swift/${HOST_VARIANT} -ltensorflow -ltensorflow_framework")
22+
endif()
23+
endfunction()
124
function(lldb_tablegen)
225
# Syntax:
326
# lldb_tablegen output-file [tablegen-arg ...] SOURCE source-file
@@ -136,6 +159,11 @@ function(add_lldb_library name)
136159
else()
137160
set_target_properties(${name} PROPERTIES FOLDER "lldb libraries")
138161
endif()
162+
163+
# SWIFT_ENABLE_TENSORFLOW
164+
if(SWIFT_ENABLE_TENSORFLOW)
165+
add_tensorflow_compiler_flags(${name})
166+
endif()
139167
endfunction(add_lldb_library)
140168

141169
function(add_lldb_executable name)
@@ -193,6 +221,10 @@ function(add_lldb_executable name)
193221
lldb_add_post_install_steps_darwin(${name} ${ARG_INSTALL_PREFIX})
194222
endif()
195223
endif()
224+
# SWIFT_ENABLE_TENSORFLOW
225+
if(SWIFT_ENABLE_TENSORFLOW)
226+
add_tensorflow_compiler_flags(${name})
227+
endif()
196228
endfunction()
197229

198230

lldb/cmake/modules/LLDBConfig.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ if (NOT LLDB_DISABLE_PYTHON)
229229
add_definitions( -DLLDB_PYTHON_HOME="${LLDB_PYTHON_HOME}" )
230230
endif()
231231
else()
232+
# SWIFT_ENABLE_TENSORFLOW
233+
# Make it so that LLDB can find Python 3.6 or Python 3.7.
234+
set(Python_ADDITIONAL_VERSIONS 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0 2.7 2.6 2.5)
232235
find_package(PythonInterp REQUIRED)
233236
find_package(PythonLibs REQUIRED)
234237
endif()

lldb/include/lldb/API/LLDB.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
#include "lldb/API/SBStream.h"
5555
#include "lldb/API/SBStringList.h"
5656
#include "lldb/API/SBStructuredData.h"
57+
// SWIFT_ENABLE_TENSORFLOW
58+
#include "lldb/API/SBCompletionMatch.h"
59+
#include "lldb/API/SBCompletionResponse.h"
5760
#include "lldb/API/SBSymbol.h"
5861
#include "lldb/API/SBSymbolContext.h"
5962
#include "lldb/API/SBSymbolContextList.h"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//===-- SBCompletionMatch.h -------------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLDB_SBCompletionMatch_h_
14+
#define LLDB_SBCompletionMatch_h_
15+
16+
#include "lldb/API/SBDefines.h"
17+
#include "lldb/Target/CompletionMatch.h"
18+
19+
namespace lldb {
20+
21+
class LLDB_API SBCompletionMatch {
22+
public:
23+
SBCompletionMatch();
24+
25+
SBCompletionMatch(const SBCompletionMatch &rhs);
26+
27+
const SBCompletionMatch &operator=(const SBCompletionMatch &rhs);
28+
29+
const char *GetDisplay() const;
30+
31+
const char *GetInsertable() const;
32+
33+
protected:
34+
friend class SBCompletionResponse;
35+
36+
SBCompletionMatch(const lldb_private::CompletionMatch *response);
37+
38+
private:
39+
std::unique_ptr<lldb_private::CompletionMatch> m_opaque_ap;
40+
};
41+
42+
} // namespace lldb
43+
44+
#endif // LLDB_SBCompletionMatch_h_
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//===-- SBCompletionResponse.h ----------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLDB_SBCompletionResponse_h_
14+
#define LLDB_SBCompletionResponse_h_
15+
16+
#include "lldb/API/SBDefines.h"
17+
#include "lldb/Target/CompletionResponse.h"
18+
19+
namespace lldb {
20+
21+
class LLDB_API SBCompletionResponse {
22+
public:
23+
SBCompletionResponse();
24+
25+
SBCompletionResponse(const SBCompletionResponse &rhs);
26+
27+
const SBCompletionResponse &operator=(const SBCompletionResponse &rhs);
28+
29+
const char *GetErrorMessage() const;
30+
31+
const char *GetPrefix() const;
32+
33+
uint32_t GetNumMatches() const;
34+
35+
SBCompletionMatch GetMatchAtIndex(size_t idx) const;
36+
37+
protected:
38+
friend class SBTarget;
39+
40+
SBCompletionResponse(const lldb_private::CompletionResponse *response);
41+
42+
private:
43+
std::unique_ptr<lldb_private::CompletionResponse> m_opaque_ap;
44+
};
45+
46+
} // namespace lldb
47+
48+
#endif // LLDB_SBCompletionResponse_h_

lldb/include/lldb/API/SBDefines.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class LLDB_API SBCommandPluginInterface;
3333
class LLDB_API SBCommandReturnObject;
3434
class LLDB_API SBCommunication;
3535
class LLDB_API SBCompileUnit;
36+
class LLDB_API SBCompletionMatch;
37+
class LLDB_API SBCompletionResponse;
3638
class LLDB_API SBData;
3739
class LLDB_API SBDebugger;
3840
class LLDB_API SBDeclaration;

lldb/include/lldb/API/SBTarget.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,12 @@ class LLDB_API SBTarget {
824824
lldb::SBValue EvaluateExpression(const char *expr,
825825
const SBExpressionOptions &options);
826826

827+
// SWIFT_ENABLE_TENSORFLOW
828+
SBCompletionResponse
829+
CompleteCode(lldb::LanguageType language,
830+
const lldb::SBSymbolContext *symbol_context,
831+
const char *current_code);
832+
827833
lldb::addr_t GetStackRedZoneSize();
828834

829835
lldb::SBLaunchInfo GetLaunchInfo() const;

lldb/include/lldb/Symbol/SwiftASTContext.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,19 @@ class SwiftASTContext : public TypeSystem {
210210
m_platform_sdk_path = path;
211211
}
212212

213+
const char *GetResourceDir() const {
214+
if (m_resource_dir.empty())
215+
return NULL;
216+
return m_resource_dir.c_str();
217+
}
218+
219+
void SetResourceDir(const char *path) {
220+
if (path)
221+
m_resource_dir = path;
222+
else
223+
m_resource_dir.clear();
224+
}
225+
213226
const swift::SearchPathOptions *GetSearchPathOptions() const;
214227

215228
/// \return the ExtraArgs of the ClangImporterOptions.
@@ -814,6 +827,8 @@ class SwiftASTContext : public TypeSystem {
814827
lldb_private::Process *m_process = nullptr;
815828
Module *m_module = nullptr;
816829
std::string m_platform_sdk_path;
830+
std::string m_resource_dir;
831+
817832

818833
typedef std::map<Module *, std::vector<lldb::DataBufferSP>> ASTFileDataMap;
819834
ASTFileDataMap m_ast_file_data_map;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===--- CompletionMatch.h --------------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef CompletionMatch_h_
14+
#define CompletionMatch_h_
15+
16+
#include <string>
17+
18+
namespace lldb_private {
19+
20+
struct CompletionMatch {
21+
std::string Display;
22+
std::string Insertable;
23+
};
24+
25+
} // namespace lldb_private
26+
27+
#endif // CompletionMatch_h_
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===--- CompletionResponse.h -----------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef CompletionResponse_h_
14+
#define CompletionResponse_h_
15+
16+
#include "lldb/Target/CompletionMatch.h"
17+
18+
#include <string>
19+
#include <vector>
20+
21+
namespace lldb_private {
22+
23+
struct CompletionResponse {
24+
std::string ErrorMessage;
25+
std::string Prefix;
26+
std::vector<CompletionMatch> Matches;
27+
28+
static CompletionResponse error(const std::string &ErrorMessage) {
29+
CompletionResponse Response;
30+
Response.ErrorMessage = ErrorMessage;
31+
return Response;
32+
}
33+
};
34+
35+
} // namespace lldb_private
36+
37+
#endif // CompletionResponse_h_

lldb/include/lldb/Target/Language.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "lldb/DataFormatters/DumpValueObjectOptions.h"
2121
#include "lldb/DataFormatters/FormatClasses.h"
2222
#include "lldb/DataFormatters/StringPrinter.h"
23+
// SWIFT_ENABLE_TENSORFLOW
24+
#include "lldb/Target/CompletionResponse.h"
2325
#include "lldb/Symbol/TypeSystem.h"
2426
#include "lldb/lldb-private.h"
2527
#include "lldb/lldb-public.h"
@@ -235,6 +237,10 @@ class Language : public PluginInterface {
235237
static void GetDefaultExceptionResolverDescription(bool catch_on,
236238
bool throw_on, Stream &s);
237239

240+
// SWIFT_ENABLE_TENSORFLOW
241+
virtual CompletionResponse CompleteCode(ExecutionContextScope &exe_scope,
242+
const std::string &entered_code);
243+
238244
// These are accessors for general information about the Languages lldb knows
239245
// about:
240246

lldb/include/lldb/Target/SwiftLanguageRuntime.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,14 @@ class SwiftLanguageRuntime : public LanguageRuntime {
451451
std::unique_ptr<swift::remoteAST::RemoteASTContext>>
452452
m_remote_ast_contexts;
453453

454+
// [BEGIN GOOGLE] Change const char * -> std::string
454455
/// Uses ConstStrings as keys to avoid storing the strings twice.
455-
llvm::DenseMap<const char *, lldb::SyntheticChildrenSP> m_bridged_synthetics_map;
456+
std::map<std::string, lldb::SyntheticChildrenSP> m_bridged_synthetics_map;
456457

457458
/// Cached member variable offsets.
458-
using MemberID = std::pair<const swift::TypeBase *, const char *>;
459-
llvm::DenseMap<MemberID, uint64_t> m_member_offsets;
459+
using MemberID = std::pair<const swift::TypeBase *, std::string>;
460+
std::map<MemberID, uint64_t> m_member_offsets;
461+
// [END GOOGLE]
460462

461463
CompilerType m_box_metadata_type;
462464

lldb/include/lldb/Target/Target.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include "lldb/Symbol/SymbolContext.h"
3535
#include "lldb/Symbol/TypeSystem.h"
3636
#include "lldb/Target/ABI.h"
37+
// SWIFT_ENABLE_TENSORFLOW
38+
#include "lldb/Target/CompletionResponse.h"
3739
#include "lldb/Target/ExecutionContextScope.h"
3840
#include "lldb/Target/PathMappingList.h"
3941
#include "lldb/Target/SectionLoadHistory.h"
@@ -1179,6 +1181,10 @@ class Target : public std::enable_shared_from_this<Target>,
11791181
const EvaluateExpressionOptions &options = EvaluateExpressionOptions(),
11801182
std::string *fixed_expression = nullptr, ValueObject *ctx_obj = nullptr);
11811183

1184+
// SWIFT_ENABLE_TENSORFLOW
1185+
CompletionResponse CompleteCode(lldb::LanguageType language,
1186+
llvm::StringRef current_code);
1187+
11821188
// Look up a symbol by name and type in both the target's symbols and the
11831189
// persistent symbols from the
11841190
// expression parser. The symbol_type is ignored in that case, for now we

lldb/lit/Swift/MissingVFSOverlay.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Test that error messages from constructing ClangImporter
22
# are surfaced to the user.
33

4+
# TODO(TF-659): Reenable this test.
5+
# REQUIRES: TF-659
6+
47
# RUN: rm -rf %t && mkdir %t && cd %t
58
# RUN: cp %p/../../packages/Python/lldbsuite/test/lang/swift/deserialization_failure/Inputs/main.swift %t/main.swift
69
# RUN: echo "{ 'version': 0, 'roots': [] }" >%t/overlay.yaml

lldb/lit/SwiftREPL/OpenClass.test

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// RUN: %lldb --repl < %s 2>&1 | FileCheck %s
1+
// TODO(TF-493): Re-enable
2+
// RUN: echo "disabled"
3+
// UN: %lldb --repl < %s 2>&1 | FileCheck %s
24

35
class Foo {
46
// Don't make any of these 'open'.

0 commit comments

Comments
 (0)