Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / tools / lldb-fuzzer / lldb-commandinterpreter-fuzzer / lldb-commandinterpreter-fuzzer.cpp
blob036954838b057818289cf997746ddeb04d81c114
1 //===-- lldb-commandinterpreter-fuzzer.cpp -------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===---------------------------------------------------------------------===//
9 #include <string>
11 #include "lldb/API/SBCommandInterpreter.h"
12 #include "lldb/API/SBCommandInterpreterRunOptions.h"
13 #include "lldb/API/SBCommandReturnObject.h"
14 #include "lldb/API/SBDebugger.h"
15 #include "lldb/API/SBTarget.h"
17 using namespace lldb;
19 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
20 SBDebugger::Initialize();
21 return 0;
24 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
25 // Convert the data into a null-terminated string
26 std::string str((char *)data, size);
28 // Create a debugger and a dummy target
29 SBDebugger debugger = SBDebugger::Create(false);
30 SBTarget target = debugger.GetDummyTarget();
32 // Create a command interpreter for the current debugger
33 // A return object is needed to run the command interpreter
34 SBCommandReturnObject ro = SBCommandReturnObject();
35 SBCommandInterpreter ci = debugger.GetCommandInterpreter();
37 // Use the fuzzer generated input as input for the command interpreter
38 if (ci.IsValid()) {
39 ci.HandleCommand(str.c_str(), ro, false);
42 debugger.DeleteTarget(target);
43 SBDebugger::Destroy(debugger);
44 SBModule::GarbageCollectAllocatedModules();
46 return 0;