56 lines · cpp
1//===- FileLineColLocBreakpointManager.cpp - MLIR Optimizer Driver --------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "mlir/Debug/BreakpointManagers/FileLineColLocBreakpointManager.h"10 11using namespace mlir;12using namespace mlir::tracing;13 14FailureOr<std::tuple<StringRef, int64_t, int64_t>>15FileLineColLocBreakpoint::parseFromString(StringRef str,16 function_ref<void(Twine)> diag) {17 // Watch at debug locations arguments are expected to be in the form:18 // `fileName:line:col`, `fileName:line`, or `fileName`.19 20 if (str.empty()) {21 if (diag)22 diag("error: initializing FileLineColLocBreakpoint with empty file name");23 return failure();24 }25 26 // This logic is complex because on Windows `:` is a comment valid path27 // character: `C:\...`.28 auto [fileLine, colStr] = str.rsplit(':');29 auto [file, lineStr] = fileLine.rsplit(':');30 // Extract the line and column value31 int64_t line = -1, col = -1;32 if (lineStr.empty()) {33 // No candidate for line number, try to use the column string as line34 // instead.35 file = fileLine;36 if (!colStr.empty() && colStr.getAsInteger(0, line))37 file = str;38 } else {39 if (lineStr.getAsInteger(0, line)) {40 // Failed to parse a line number, try to use the column string as line41 // instead. If this failed as well, the entire string is the file name.42 file = fileLine;43 if (colStr.getAsInteger(0, line))44 file = str;45 } else {46 // We successfully parsed a line number, try to parse the column number.47 // This shouldn't fail, or the entire string is the file name.48 if (colStr.getAsInteger(0, col)) {49 file = str;50 line = -1;51 }52 }53 }54 return std::tuple<StringRef, int64_t, int64_t>{file, line, col};55}56