1 //===- DebuggerExecutionContextHook.h - Debugger Support --------*- C++ -*-===// 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 //===----------------------------------------------------------------------===// 8 // 9 // This file contains a set of C API functions that are used by the debugger to 10 // interact with the ExecutionContext. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef MLIR_SUPPORT_DEBUGGEREXECUTIONCONTEXTHOOK_H 15 #define MLIR_SUPPORT_DEBUGGEREXECUTIONCONTEXTHOOK_H 16 17 #include "mlir-c/IR.h" 18 #include "mlir/Debug/ExecutionContext.h" 19 #include "llvm/Support/Compiler.h" 20 21 extern "C" { 22 struct MLIRBreakpoint; 23 struct MLIRIRunit; 24 typedef struct MLIRBreakpoint *BreakpointHandle; 25 typedef struct MLIRIRunit *irunitHandle; 26 27 /// This is used by the debugger to control what to do after a breakpoint is 28 /// hit. See tracing::ExecutionContext::Control for more information. 29 void mlirDebuggerSetControl(int controlOption); 30 31 /// Print the available context for the current Action. 32 void mlirDebuggerPrintContext(); 33 34 /// Print the current action backtrace. 35 void mlirDebuggerPrintActionBacktrace(bool withContext); 36 37 //===----------------------------------------------------------------------===// 38 // Cursor Management: The cursor is used to select an IRUnit from the context 39 // and to navigate through the IRUnit hierarchy. 40 //===----------------------------------------------------------------------===// 41 42 /// Print the current IR unit cursor. 43 void mlirDebuggerCursorPrint(bool withRegion); 44 45 /// Select the IR unit from the current context by ID. 46 void mlirDebuggerCursorSelectIRUnitFromContext(int index); 47 48 /// Select the parent IR unit of the provided IR unit, or print an error if the 49 /// IR unit has no parent. 50 void mlirDebuggerCursorSelectParentIRUnit(); 51 52 /// Select the child IR unit at the provided index, print an error if the index 53 /// is out of bound. For example if the irunit is an operation, the children IR 54 /// units will be the operation's regions. 55 void mlirDebuggerCursorSelectChildIRUnit(int index); 56 57 /// Return the next IR unit logically in the IR. For example if the irunit is a 58 /// Region the next IR unit will be the next region in the parent operation or 59 /// nullptr if there is no next region. 60 void mlirDebuggerCursorSelectPreviousIRUnit(); 61 62 /// Return the previous IR unit logically in the IR. For example if the irunit 63 /// is a Region, the previous IR unit will be the previous region in the parent 64 /// operation or nullptr if there is no previous region. 65 void mlirDebuggerCursorSelectNextIRUnit(); 66 67 //===----------------------------------------------------------------------===// 68 // Breakpoint Management 69 //===----------------------------------------------------------------------===// 70 71 /// Enable the provided breakpoint. 72 void mlirDebuggerEnableBreakpoint(BreakpointHandle breakpoint); 73 74 /// Disable the provided breakpoint. 75 void mlirDebuggerDisableBreakpoint(BreakpointHandle breakpoint); 76 77 /// Add a breakpoint matching exactly the provided tag. 78 BreakpointHandle mlirDebuggerAddTagBreakpoint(const char *tag); 79 80 /// Add a breakpoint matching a pattern by name. 81 void mlirDebuggerAddRewritePatternBreakpoint(const char *patternNameInfo); 82 83 /// Add a breakpoint matching a file, line and column. 84 void mlirDebuggerAddFileLineColLocBreakpoint(const char *file, int line, 85 int col); 86 87 } // extern "C" 88 89 namespace mlir { 90 // Setup the debugger hooks as a callback on the provided ExecutionContext. 91 void setupDebuggerExecutionContextHook( 92 tracing::ExecutionContext &executionContext); 93 94 } // namespace mlir 95 96 #endif // MLIR_SUPPORT_DEBUGGEREXECUTIONCONTEXTHOOK_H 97