1061da546Spatrick //===-- JSONUtils.h ---------------------------------------------*- C++ -*-===// 2061da546Spatrick // 3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information. 5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6061da546Spatrick // 7061da546Spatrick //===----------------------------------------------------------------------===// 8061da546Spatrick 9dda28197Spatrick #ifndef LLDB_TOOLS_LLDB_VSCODE_JSONUTILS_H 10dda28197Spatrick #define LLDB_TOOLS_LLDB_VSCODE_JSONUTILS_H 11061da546Spatrick 12061da546Spatrick #include "VSCodeForward.h" 13dda28197Spatrick #include "lldb/API/SBModule.h" 14be691f3bSpatrick #include "llvm/ADT/StringRef.h" 15be691f3bSpatrick #include "llvm/Support/JSON.h" 16be691f3bSpatrick #include <cstdint> 17*f6aab3d8Srobert #include <optional> 18061da546Spatrick 19061da546Spatrick namespace lldb_vscode { 20061da546Spatrick 21061da546Spatrick /// Emplace a StringRef in a json::Object after enusring that the 22061da546Spatrick /// string is valid UTF8. If not, first call llvm::json::fixUTF8 23061da546Spatrick /// before emplacing. 24061da546Spatrick /// 25061da546Spatrick /// \param[in] obj 26061da546Spatrick /// A JSON object that we will attempt to emplace the value in 27061da546Spatrick /// 28061da546Spatrick /// \param[in] key 29061da546Spatrick /// The key to use when emplacing the value 30061da546Spatrick /// 31061da546Spatrick /// \param[in] str 32061da546Spatrick /// The string to emplace 33061da546Spatrick void EmplaceSafeString(llvm::json::Object &obj, llvm::StringRef key, 34061da546Spatrick llvm::StringRef str); 35061da546Spatrick 36061da546Spatrick /// Extract simple values as a string. 37061da546Spatrick /// 38061da546Spatrick /// \param[in] value 39061da546Spatrick /// A JSON value to extract the string from. 40061da546Spatrick /// 41061da546Spatrick /// \return 42061da546Spatrick /// A llvm::StringRef that contains the string value, or an empty 43061da546Spatrick /// string if \a value isn't a string. 44061da546Spatrick llvm::StringRef GetAsString(const llvm::json::Value &value); 45061da546Spatrick 46061da546Spatrick /// Extract the string value for the specified key from the 47061da546Spatrick /// specified object. 48061da546Spatrick /// 49061da546Spatrick /// \param[in] obj 50061da546Spatrick /// A JSON object that we will attempt to extract the value from 51061da546Spatrick /// 52061da546Spatrick /// \param[in] key 53061da546Spatrick /// The key to use when extracting the value 54061da546Spatrick /// 55061da546Spatrick /// \return 56061da546Spatrick /// A llvm::StringRef that contains the string value for the 57061da546Spatrick /// specified \a key, or an empty string if there is no key that 58061da546Spatrick /// matches or if the value is not a string. 59061da546Spatrick llvm::StringRef GetString(const llvm::json::Object &obj, llvm::StringRef key); 60061da546Spatrick llvm::StringRef GetString(const llvm::json::Object *obj, llvm::StringRef key); 61061da546Spatrick 62061da546Spatrick /// Extract the unsigned integer value for the specified key from 63061da546Spatrick /// the specified object. 64061da546Spatrick /// 65061da546Spatrick /// \param[in] obj 66061da546Spatrick /// A JSON object that we will attempt to extract the value from 67061da546Spatrick /// 68061da546Spatrick /// \param[in] key 69061da546Spatrick /// The key to use when extracting the value 70061da546Spatrick /// 71061da546Spatrick /// \return 72061da546Spatrick /// The unsigned integer value for the specified \a key, or 73061da546Spatrick /// \a fail_value if there is no key that matches or if the 74061da546Spatrick /// value is not an integer. 75061da546Spatrick uint64_t GetUnsigned(const llvm::json::Object &obj, llvm::StringRef key, 76061da546Spatrick uint64_t fail_value); 77061da546Spatrick uint64_t GetUnsigned(const llvm::json::Object *obj, llvm::StringRef key, 78061da546Spatrick uint64_t fail_value); 79061da546Spatrick 80061da546Spatrick /// Extract the boolean value for the specified key from the 81061da546Spatrick /// specified object. 82061da546Spatrick /// 83061da546Spatrick /// \param[in] obj 84061da546Spatrick /// A JSON object that we will attempt to extract the value from 85061da546Spatrick /// 86061da546Spatrick /// \param[in] key 87061da546Spatrick /// The key to use when extracting the value 88061da546Spatrick /// 89061da546Spatrick /// \return 90061da546Spatrick /// The boolean value for the specified \a key, or \a fail_value 91061da546Spatrick /// if there is no key that matches or if the value is not a 92061da546Spatrick /// boolean value of an integer. 93061da546Spatrick bool GetBoolean(const llvm::json::Object &obj, llvm::StringRef key, 94061da546Spatrick bool fail_value); 95061da546Spatrick bool GetBoolean(const llvm::json::Object *obj, llvm::StringRef key, 96061da546Spatrick bool fail_value); 97061da546Spatrick 98061da546Spatrick /// Extract the signed integer for the specified key from the 99061da546Spatrick /// specified object. 100061da546Spatrick /// 101061da546Spatrick /// \param[in] obj 102061da546Spatrick /// A JSON object that we will attempt to extract the value from 103061da546Spatrick /// 104061da546Spatrick /// \param[in] key 105061da546Spatrick /// The key to use when extracting the value 106061da546Spatrick /// 107061da546Spatrick /// \return 108061da546Spatrick /// The signed integer value for the specified \a key, or 109061da546Spatrick /// \a fail_value if there is no key that matches or if the 110061da546Spatrick /// value is not an integer. 111061da546Spatrick int64_t GetSigned(const llvm::json::Object &obj, llvm::StringRef key, 112061da546Spatrick int64_t fail_value); 113061da546Spatrick int64_t GetSigned(const llvm::json::Object *obj, llvm::StringRef key, 114061da546Spatrick int64_t fail_value); 115061da546Spatrick 116061da546Spatrick /// Check if the specified key exists in the specified object. 117061da546Spatrick /// 118061da546Spatrick /// \param[in] obj 119061da546Spatrick /// A JSON object that we will attempt to extract the value from 120061da546Spatrick /// 121061da546Spatrick /// \param[in] key 122061da546Spatrick /// The key to check for 123061da546Spatrick /// 124061da546Spatrick /// \return 125061da546Spatrick /// \b True if the key exists in the \a obj, \b False otherwise. 126061da546Spatrick bool ObjectContainsKey(const llvm::json::Object &obj, llvm::StringRef key); 127061da546Spatrick 128061da546Spatrick /// Extract an array of strings for the specified key from an object. 129061da546Spatrick /// 130061da546Spatrick /// String values in the array will be extracted without any quotes 131061da546Spatrick /// around them. Numbers and Booleans will be converted into 132061da546Spatrick /// strings. Any NULL, array or objects values in the array will be 133061da546Spatrick /// ignored. 134061da546Spatrick /// 135061da546Spatrick /// \param[in] obj 136061da546Spatrick /// A JSON object that we will attempt to extract the array from 137061da546Spatrick /// 138061da546Spatrick /// \param[in] key 139061da546Spatrick /// The key to use when extracting the value 140061da546Spatrick /// 141061da546Spatrick /// \return 142061da546Spatrick /// An array of string values for the specified \a key, or 143061da546Spatrick /// \a fail_value if there is no key that matches or if the 144061da546Spatrick /// value is not an array or all items in the array are not 145061da546Spatrick /// strings, numbers or booleans. 146061da546Spatrick std::vector<std::string> GetStrings(const llvm::json::Object *obj, 147061da546Spatrick llvm::StringRef key); 148061da546Spatrick 149061da546Spatrick /// Fill a response object given the request object. 150061da546Spatrick /// 151061da546Spatrick /// The \a response object will get its "type" set to "response", 152061da546Spatrick /// the "seq" set to zero, "response_seq" set to the "seq" value from 153061da546Spatrick /// \a request, "command" set to the "command" from \a request, 154061da546Spatrick /// and "success" set to true. 155061da546Spatrick /// 156061da546Spatrick /// \param[in] request 157061da546Spatrick /// The request object received from a call to VSCode::ReadJSON(). 158061da546Spatrick /// 159061da546Spatrick /// \param[in,out] response 160061da546Spatrick /// An empty llvm::json::Object object that will be filled 161061da546Spatrick /// in as noted in description. 162061da546Spatrick void FillResponse(const llvm::json::Object &request, 163061da546Spatrick llvm::json::Object &response); 164061da546Spatrick 165061da546Spatrick /// Emplace the string value from an SBValue into the supplied object 166061da546Spatrick /// using \a key as the key that will contain the value. 167061da546Spatrick /// 168061da546Spatrick /// The value is what we will display in VS Code. Some SBValue objects 169061da546Spatrick /// can have a value and/or a summary. If a value has both, we 170061da546Spatrick /// combine the value and the summary into one string. If we only have a 171061da546Spatrick /// value or summary, then that is considered the value. If there is 172061da546Spatrick /// no value and no summary then the value is the type name followed by 173061da546Spatrick /// the address of the type if it has an address. 174061da546Spatrick /// 175061da546Spatrick /// 176061da546Spatrick /// \param[in] v 177061da546Spatrick /// A lldb::SBValue object to extract the string value from 178061da546Spatrick /// 179061da546Spatrick /// 180061da546Spatrick /// \param[in] object 181061da546Spatrick /// The object to place the value object into 182061da546Spatrick /// 183061da546Spatrick /// 184061da546Spatrick /// \param[in] key 185061da546Spatrick /// The key name to use when inserting the value object we create 186061da546Spatrick void SetValueForKey(lldb::SBValue &v, llvm::json::Object &object, 187061da546Spatrick llvm::StringRef key); 188061da546Spatrick 189dda28197Spatrick /// Converts \a bp to a JSON value and appends the first valid location to the 190061da546Spatrick /// \a breakpoints array. 191061da546Spatrick /// 192061da546Spatrick /// \param[in] bp 193dda28197Spatrick /// A LLDB breakpoint object which will get the first valid location 194dda28197Spatrick /// extracted and converted into a JSON object in the \a breakpoints array 195061da546Spatrick /// 196061da546Spatrick /// \param[in] breakpoints 197061da546Spatrick /// A JSON array that will get a llvm::json::Value for \a bp 198061da546Spatrick /// appended to it. 199dda28197Spatrick /// 200dda28197Spatrick /// \param[in] request_path 201dda28197Spatrick /// An optional source path to use when creating the "Source" object of this 202dda28197Spatrick /// breakpoint. If not specified, the "Source" object is created from the 203dda28197Spatrick /// breakpoint's address' LineEntry. It is useful to ensure the same source 204dda28197Spatrick /// paths provided by the setBreakpoints request are returned to the IDE. 205dda28197Spatrick /// 206dda28197Spatrick /// \param[in] request_line 207dda28197Spatrick /// An optional line to use when creating the "Breakpoint" object to append. 208dda28197Spatrick /// It is used if the breakpoint has no valid locations. 209dda28197Spatrick /// It is useful to ensure the same line 210dda28197Spatrick /// provided by the setBreakpoints request are returned to the IDE as a 211dda28197Spatrick /// fallback. 212*f6aab3d8Srobert void AppendBreakpoint( 213*f6aab3d8Srobert lldb::SBBreakpoint &bp, llvm::json::Array &breakpoints, 214*f6aab3d8Srobert std::optional<llvm::StringRef> request_path = std::nullopt, 215*f6aab3d8Srobert std::optional<uint32_t> request_line = std::nullopt); 216061da546Spatrick 217061da546Spatrick /// Converts breakpoint location to a Visual Studio Code "Breakpoint" 218061da546Spatrick /// 219dda28197Spatrick /// \param[in] bp 220dda28197Spatrick /// A LLDB breakpoint object to convert into a JSON value 221dda28197Spatrick /// 222dda28197Spatrick /// \param[in] request_path 223dda28197Spatrick /// An optional source path to use when creating the "Source" object of this 224dda28197Spatrick /// breakpoint. If not specified, the "Source" object is created from the 225dda28197Spatrick /// breakpoint's address' LineEntry. It is useful to ensure the same source 226dda28197Spatrick /// paths provided by the setBreakpoints request are returned to the IDE. 227dda28197Spatrick /// 228dda28197Spatrick /// \param[in] request_line 229dda28197Spatrick /// An optional line to use when creating the resulting "Breakpoint" object. 230dda28197Spatrick /// It is used if the breakpoint has no valid locations. 231dda28197Spatrick /// It is useful to ensure the same line 232dda28197Spatrick /// provided by the setBreakpoints request are returned to the IDE as a 233dda28197Spatrick /// fallback. 234061da546Spatrick /// 235061da546Spatrick /// \return 236061da546Spatrick /// A "Breakpoint" JSON object with that follows the formal JSON 237061da546Spatrick /// definition outlined by Microsoft. 238dda28197Spatrick llvm::json::Value 239dda28197Spatrick CreateBreakpoint(lldb::SBBreakpoint &bp, 240*f6aab3d8Srobert std::optional<llvm::StringRef> request_path = std::nullopt, 241*f6aab3d8Srobert std::optional<uint32_t> request_line = std::nullopt); 242dda28197Spatrick 243dda28197Spatrick /// Converts a LLDB module to a VS Code DAP module for use in "modules" events. 244dda28197Spatrick /// 245dda28197Spatrick /// \param[in] module 246dda28197Spatrick /// A LLDB module object to convert into a JSON value 247dda28197Spatrick /// 248dda28197Spatrick /// \return 249dda28197Spatrick /// A "Module" JSON object with that follows the formal JSON 250dda28197Spatrick /// definition outlined by Microsoft. 251dda28197Spatrick llvm::json::Value CreateModule(lldb::SBModule &module); 252061da546Spatrick 253061da546Spatrick /// Create a "Event" JSON object using \a event_name as the event name 254061da546Spatrick /// 255061da546Spatrick /// \param[in] event_name 256061da546Spatrick /// The string value to use for the "event" key in the JSON object. 257061da546Spatrick /// 258061da546Spatrick /// \return 259061da546Spatrick /// A "Event" JSON object with that follows the formal JSON 260061da546Spatrick /// definition outlined by Microsoft. 261061da546Spatrick llvm::json::Object CreateEventObject(const llvm::StringRef event_name); 262061da546Spatrick 263061da546Spatrick /// Create a "ExceptionBreakpointsFilter" JSON object as described in 264061da546Spatrick /// the Visual Studio Code debug adaptor definition. 265061da546Spatrick /// 266061da546Spatrick /// \param[in] bp 267dda28197Spatrick /// The exception breakpoint object to use 268061da546Spatrick /// 269061da546Spatrick /// \return 270061da546Spatrick /// A "ExceptionBreakpointsFilter" JSON object with that follows 271061da546Spatrick /// the formal JSON definition outlined by Microsoft. 272061da546Spatrick llvm::json::Value 273061da546Spatrick CreateExceptionBreakpointFilter(const ExceptionBreakpoint &bp); 274061da546Spatrick 275061da546Spatrick /// Create a "Scope" JSON object as described in the Visual Studio Code 276061da546Spatrick /// debug adaptor definition. 277061da546Spatrick /// 278061da546Spatrick /// \param[in] name 279061da546Spatrick /// The value to place into the "name" key 280061da546Spatrick // 281061da546Spatrick /// \param[in] variablesReference 282061da546Spatrick /// The value to place into the "variablesReference" key 283061da546Spatrick // 284061da546Spatrick /// \param[in] namedVariables 285061da546Spatrick /// The value to place into the "namedVariables" key 286061da546Spatrick // 287061da546Spatrick /// \param[in] expensive 288061da546Spatrick /// The value to place into the "expensive" key 289061da546Spatrick /// 290061da546Spatrick /// \return 291061da546Spatrick /// A "Scope" JSON object with that follows the formal JSON 292061da546Spatrick /// definition outlined by Microsoft. 293061da546Spatrick llvm::json::Value CreateScope(const llvm::StringRef name, 294061da546Spatrick int64_t variablesReference, 295061da546Spatrick int64_t namedVariables, bool expensive); 296061da546Spatrick 297061da546Spatrick /// Create a "Source" JSON object as described in the Visual Studio Code 298061da546Spatrick /// debug adaptor definition. 299061da546Spatrick /// 300061da546Spatrick /// \param[in] line_entry 301061da546Spatrick /// The LLDB line table to use when populating out the "Source" 302061da546Spatrick /// object 303061da546Spatrick /// 304061da546Spatrick /// \return 305061da546Spatrick /// A "Source" JSON object with that follows the formal JSON 306061da546Spatrick /// definition outlined by Microsoft. 307061da546Spatrick llvm::json::Value CreateSource(lldb::SBLineEntry &line_entry); 308061da546Spatrick 309dda28197Spatrick /// Create a "Source" object for a given source path. 310dda28197Spatrick /// 311dda28197Spatrick /// \param[in] source_path 312dda28197Spatrick /// The path to the source to use when creating the "Source" object. 313dda28197Spatrick /// 314dda28197Spatrick /// \return 315dda28197Spatrick /// A "Source" JSON object that follows the formal JSON 316dda28197Spatrick /// definition outlined by Microsoft. 317dda28197Spatrick llvm::json::Value CreateSource(llvm::StringRef source_path); 318dda28197Spatrick 319061da546Spatrick /// Create a "Source" object for a given frame. 320061da546Spatrick /// 321061da546Spatrick /// When there is no source file information for a stack frame, we will 322061da546Spatrick /// create disassembly for a function and store a permanent 323061da546Spatrick /// "sourceReference" that contains the textual disassembly for a 324061da546Spatrick /// function along with address to line information. The "Source" object 325061da546Spatrick /// that is created will contain a "sourceReference" that the VSCode 326061da546Spatrick /// protocol can later fetch as text in order to display disassembly. 327061da546Spatrick /// The PC will be extracted from the frame and the disassembly line 328061da546Spatrick /// within the source referred to by "sourceReference" will be filled 329061da546Spatrick /// in. 330061da546Spatrick /// 331061da546Spatrick /// \param[in] frame 332061da546Spatrick /// The LLDB stack frame to use when populating out the "Source" 333061da546Spatrick /// object. 334061da546Spatrick /// 335061da546Spatrick /// \param[out] disasm_line 336061da546Spatrick /// The line within the "sourceReference" file that the PC from 337061da546Spatrick /// \a frame matches. 338061da546Spatrick /// 339061da546Spatrick /// \return 340061da546Spatrick /// A "Source" JSON object with that follows the formal JSON 341061da546Spatrick /// definition outlined by Microsoft. 342061da546Spatrick llvm::json::Value CreateSource(lldb::SBFrame &frame, int64_t &disasm_line); 343061da546Spatrick 344061da546Spatrick /// Create a "StackFrame" object for a LLDB frame object. 345061da546Spatrick /// 346061da546Spatrick /// This function will fill in the following keys in the returned 347061da546Spatrick /// object: 348061da546Spatrick /// "id" - the stack frame ID as an integer 349061da546Spatrick /// "name" - the function name as a string 350061da546Spatrick /// "source" - source file information as a "Source" VSCode object 351061da546Spatrick /// "line" - the source file line number as an integer 352061da546Spatrick /// "column" - the source file column number as an integer 353061da546Spatrick /// 354061da546Spatrick /// \param[in] frame 355061da546Spatrick /// The LLDB stack frame to use when populating out the "StackFrame" 356061da546Spatrick /// object. 357061da546Spatrick /// 358061da546Spatrick /// \return 359061da546Spatrick /// A "StackFrame" JSON object with that follows the formal JSON 360061da546Spatrick /// definition outlined by Microsoft. 361061da546Spatrick llvm::json::Value CreateStackFrame(lldb::SBFrame &frame); 362061da546Spatrick 363061da546Spatrick /// Create a "Thread" object for a LLDB thread object. 364061da546Spatrick /// 365061da546Spatrick /// This function will fill in the following keys in the returned 366061da546Spatrick /// object: 367061da546Spatrick /// "id" - the thread ID as an integer 368061da546Spatrick /// "name" - the thread name as a string which combines the LLDB 369061da546Spatrick /// thread index ID along with the string name of the thread 370061da546Spatrick /// from the OS if it has a name. 371061da546Spatrick /// 372061da546Spatrick /// \param[in] thread 373061da546Spatrick /// The LLDB thread to use when populating out the "Thread" 374061da546Spatrick /// object. 375061da546Spatrick /// 376061da546Spatrick /// \return 377061da546Spatrick /// A "Thread" JSON object with that follows the formal JSON 378061da546Spatrick /// definition outlined by Microsoft. 379061da546Spatrick llvm::json::Value CreateThread(lldb::SBThread &thread); 380061da546Spatrick 381061da546Spatrick /// Create a "StoppedEvent" object for a LLDB thread object. 382061da546Spatrick /// 383061da546Spatrick /// This function will fill in the following keys in the returned 384061da546Spatrick /// object's "body" object: 385061da546Spatrick /// "reason" - With a valid stop reason enumeration string value 386061da546Spatrick /// that Microsoft specifies 387061da546Spatrick /// "threadId" - The thread ID as an integer 388061da546Spatrick /// "description" - a stop description (like "breakpoint 12.3") as a 389061da546Spatrick /// string 390061da546Spatrick /// "preserveFocusHint" - a boolean value that states if this thread 391061da546Spatrick /// should keep the focus in the GUI. 392061da546Spatrick /// "allThreadsStopped" - set to True to indicate that all threads 393061da546Spatrick /// stop when any thread stops. 394061da546Spatrick /// 395061da546Spatrick /// \param[in] thread 396061da546Spatrick /// The LLDB thread to use when populating out the "StoppedEvent" 397061da546Spatrick /// object. 398061da546Spatrick /// 399061da546Spatrick /// \return 400061da546Spatrick /// A "StoppedEvent" JSON object with that follows the formal JSON 401061da546Spatrick /// definition outlined by Microsoft. 402061da546Spatrick llvm::json::Value CreateThreadStopped(lldb::SBThread &thread, uint32_t stop_id); 403061da546Spatrick 404be691f3bSpatrick /// \return 405be691f3bSpatrick /// The variable name of \a value or a default placeholder. 406be691f3bSpatrick const char *GetNonNullVariableName(lldb::SBValue value); 407be691f3bSpatrick 408be691f3bSpatrick /// VSCode can't display two variables with the same name, so we need to 409be691f3bSpatrick /// distinguish them by using a suffix. 410be691f3bSpatrick /// 411be691f3bSpatrick /// If the source and line information is present, we use it as the suffix. 412be691f3bSpatrick /// Otherwise, we fallback to the variable address or register location. 413be691f3bSpatrick std::string CreateUniqueVariableNameForDisplay(lldb::SBValue v, 414be691f3bSpatrick bool is_name_duplicated); 415be691f3bSpatrick 416061da546Spatrick /// Create a "Variable" object for a LLDB thread object. 417061da546Spatrick /// 418061da546Spatrick /// This function will fill in the following keys in the returned 419061da546Spatrick /// object: 420061da546Spatrick /// "name" - the name of the variable 421061da546Spatrick /// "value" - the value of the variable as a string 422061da546Spatrick /// "type" - the typename of the variable as a string 423061da546Spatrick /// "id" - a unique identifier for a value in case there are multiple 424061da546Spatrick /// variables with the same name. Other parts of the VSCode 425061da546Spatrick /// protocol refer to values by name so this can help 426061da546Spatrick /// disambiguate such cases if a IDE passes this "id" value 427061da546Spatrick /// back down. 428061da546Spatrick /// "variablesReference" - Zero if the variable has no children, 429061da546Spatrick /// non-zero integer otherwise which can be used to expand 430061da546Spatrick /// the variable. 431061da546Spatrick /// "evaluateName" - The name of the variable to use in expressions 432061da546Spatrick /// as a string. 433061da546Spatrick /// 434061da546Spatrick /// \param[in] v 435061da546Spatrick /// The LLDB value to use when populating out the "Variable" 436061da546Spatrick /// object. 437061da546Spatrick /// 438061da546Spatrick /// \param[in] variablesReference 439061da546Spatrick /// The variable reference. Zero if this value isn't structured 440061da546Spatrick /// and has no children, non-zero if it does have children and 441061da546Spatrick /// might be asked to expand itself. 442061da546Spatrick /// 443061da546Spatrick /// \param[in] varID 444061da546Spatrick /// A unique variable identifier to help in properly identifying 445061da546Spatrick /// variables with the same name. This is an extension to the 446061da546Spatrick /// VS protocol. 447061da546Spatrick /// 448061da546Spatrick /// \param[in] format_hex 449061da546Spatrick /// It set to true the variable will be formatted as hex in 450061da546Spatrick /// the "value" key value pair for the value of the variable. 451061da546Spatrick /// 452be691f3bSpatrick /// \param[in] is_name_duplicated 453be691f3bSpatrick /// Whether the same variable name appears multiple times within the same 454be691f3bSpatrick /// context (e.g. locals). This can happen due to shadowed variables in 455be691f3bSpatrick /// nested blocks. 456be691f3bSpatrick /// 457be691f3bSpatrick /// As VSCode doesn't render two of more variables with the same name, we 458be691f3bSpatrick /// apply a suffix to distinguish duplicated variables. 459be691f3bSpatrick /// 460061da546Spatrick /// \return 461061da546Spatrick /// A "Variable" JSON object with that follows the formal JSON 462061da546Spatrick /// definition outlined by Microsoft. 463061da546Spatrick llvm::json::Value CreateVariable(lldb::SBValue v, int64_t variablesReference, 464be691f3bSpatrick int64_t varID, bool format_hex, 465be691f3bSpatrick bool is_name_duplicated = false); 466061da546Spatrick 467dda28197Spatrick llvm::json::Value CreateCompileUnit(lldb::SBCompileUnit unit); 468dda28197Spatrick 469be691f3bSpatrick /// Create a runInTerminal reverse request object 470be691f3bSpatrick /// 471be691f3bSpatrick /// \param[in] launch_request 472be691f3bSpatrick /// The original launch_request object whose fields are used to construct 473be691f3bSpatrick /// the reverse request object. 474be691f3bSpatrick /// 475be691f3bSpatrick /// \param[in] debug_adaptor_path 476be691f3bSpatrick /// Path to the current debug adaptor. It will be used to delegate the 477be691f3bSpatrick /// launch of the target. 478be691f3bSpatrick /// 479be691f3bSpatrick /// \param[in] comm_file 480be691f3bSpatrick /// The fifo file used to communicate the with the target launcher. 481be691f3bSpatrick /// 482be691f3bSpatrick /// \return 483be691f3bSpatrick /// A "runInTerminal" JSON object that follows the specification outlined by 484be691f3bSpatrick /// Microsoft. 485be691f3bSpatrick llvm::json::Object 486be691f3bSpatrick CreateRunInTerminalReverseRequest(const llvm::json::Object &launch_request, 487be691f3bSpatrick llvm::StringRef debug_adaptor_path, 488be691f3bSpatrick llvm::StringRef comm_file); 489be691f3bSpatrick 490*f6aab3d8Srobert /// Create a "Terminated" JSON object that contains statistics 491*f6aab3d8Srobert /// 492*f6aab3d8Srobert /// \return 493*f6aab3d8Srobert /// A body JSON object with debug info and breakpoint info 494*f6aab3d8Srobert llvm::json::Object CreateTerminatedEventObject(); 495*f6aab3d8Srobert 496be691f3bSpatrick /// Convert a given JSON object to a string. 497be691f3bSpatrick std::string JSONToString(const llvm::json::Value &json); 498be691f3bSpatrick 499061da546Spatrick } // namespace lldb_vscode 500061da546Spatrick 501061da546Spatrick #endif 502