1 //===-- lldb-commandinterpreter-fuzzer.cpp -------------------------------===//
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
7 //===---------------------------------------------------------------------===//
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"
19 extern "C" int LLVMFuzzerInitialize(int *argc
, char ***argv
) {
20 SBDebugger::Initialize();
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
39 ci
.HandleCommand(str
.c_str(), ro
, false);
42 debugger
.DeleteTarget(target
);
43 SBDebugger::Destroy(debugger
);
44 SBModule::GarbageCollectAllocatedModules();