[40549] | 1 | /* $Id: VBoxTpG.cpp 104620 2024-05-14 06:56:35Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[40594] | 3 | * VBox Build Tool - VBox Tracepoint Generator.
|
---|
[40549] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
[40549] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[40549] | 26 | */
|
---|
| 27 |
|
---|
| 28 |
|
---|
[57353] | 29 | /*********************************************************************************************************************************
|
---|
| 30 | * Header Files *
|
---|
| 31 | *********************************************************************************************************************************/
|
---|
[40594] | 32 | #include <VBox/VBoxTpG.h>
|
---|
| 33 |
|
---|
[40554] | 34 | #include <iprt/alloca.h>
|
---|
[40549] | 35 | #include <iprt/assert.h>
|
---|
| 36 | #include <iprt/ctype.h>
|
---|
| 37 | #include <iprt/env.h>
|
---|
[76474] | 38 | #include <iprt/errcore.h>
|
---|
[40554] | 39 | #include <iprt/file.h>
|
---|
[40549] | 40 | #include <iprt/getopt.h>
|
---|
| 41 | #include <iprt/initterm.h>
|
---|
[40554] | 42 | #include <iprt/list.h>
|
---|
[40549] | 43 | #include <iprt/mem.h>
|
---|
| 44 | #include <iprt/message.h>
|
---|
[40558] | 45 | #include <iprt/path.h>
|
---|
[40554] | 46 | #include <iprt/process.h>
|
---|
[40549] | 47 | #include <iprt/stream.h>
|
---|
| 48 | #include <iprt/string.h>
|
---|
[41117] | 49 | #include <iprt/uuid.h>
|
---|
[40549] | 50 |
|
---|
| 51 | #include "scmstream.h"
|
---|
| 52 |
|
---|
[40554] | 53 |
|
---|
[57353] | 54 | /*********************************************************************************************************************************
|
---|
| 55 | * Structures and Typedefs *
|
---|
| 56 | *********************************************************************************************************************************/
|
---|
[88956] | 57 | typedef struct VTGPROBE *PVTGPROBE;
|
---|
[40557] | 58 |
|
---|
| 59 | typedef struct VTGATTRS
|
---|
| 60 | {
|
---|
| 61 | kVTGStability enmCode;
|
---|
| 62 | kVTGStability enmData;
|
---|
| 63 | kVTGClass enmDataDep;
|
---|
| 64 | } VTGATTRS;
|
---|
| 65 | typedef VTGATTRS *PVTGATTRS;
|
---|
| 66 |
|
---|
| 67 |
|
---|
[40554] | 68 | typedef struct VTGARG
|
---|
[40549] | 69 | {
|
---|
[40557] | 70 | RTLISTNODE ListEntry;
|
---|
[41338] | 71 | /** The argument name. (heap) */
|
---|
[40878] | 72 | char *pszName;
|
---|
[41338] | 73 | /** The type presented to the tracer (in string table). */
|
---|
| 74 | const char *pszTracerType;
|
---|
| 75 | /** The argument type used in the probe method in that context. (heap) */
|
---|
| 76 | char *pszCtxType;
|
---|
| 77 | /** Argument passing format string. First and only argument is the name.
|
---|
| 78 | * (const string) */
|
---|
| 79 | const char *pszArgPassingFmt;
|
---|
| 80 | /** The type flags. */
|
---|
[40878] | 81 | uint32_t fType;
|
---|
[88956] | 82 | /** The argument number (0-based) for complaining/whatever. */
|
---|
| 83 | uint16_t iArgNo;
|
---|
| 84 | /** The probe the argument belongs to (for complaining/whatever). */
|
---|
| 85 | PVTGPROBE pProbe;
|
---|
| 86 | /** The absolute source position. */
|
---|
| 87 | size_t offSrc;
|
---|
[40554] | 88 | } VTGARG;
|
---|
| 89 | typedef VTGARG *PVTGARG;
|
---|
[40549] | 90 |
|
---|
[40554] | 91 | typedef struct VTGPROBE
|
---|
| 92 | {
|
---|
| 93 | RTLISTNODE ListEntry;
|
---|
[40619] | 94 | char *pszMangledName;
|
---|
| 95 | const char *pszUnmangledName;
|
---|
[40557] | 96 | RTLISTANCHOR ArgHead;
|
---|
[40554] | 97 | uint32_t cArgs;
|
---|
[40878] | 98 | bool fHaveLargeArgs;
|
---|
[40570] | 99 | uint32_t offArgList;
|
---|
| 100 | uint32_t iProbe;
|
---|
[88956] | 101 | size_t iLine;
|
---|
[40554] | 102 | } VTGPROBE;
|
---|
[40549] | 103 |
|
---|
[40554] | 104 | typedef struct VTGPROVIDER
|
---|
[40549] | 105 | {
|
---|
[40554] | 106 | RTLISTNODE ListEntry;
|
---|
| 107 | const char *pszName;
|
---|
[40557] | 108 |
|
---|
[40572] | 109 | uint16_t iFirstProbe;
|
---|
| 110 | uint16_t cProbes;
|
---|
| 111 |
|
---|
[40557] | 112 | VTGATTRS AttrSelf;
|
---|
| 113 | VTGATTRS AttrModules;
|
---|
| 114 | VTGATTRS AttrFunctions;
|
---|
| 115 | VTGATTRS AttrName;
|
---|
| 116 | VTGATTRS AttrArguments;
|
---|
| 117 |
|
---|
[40554] | 118 | RTLISTANCHOR ProbeHead;
|
---|
| 119 | } VTGPROVIDER;
|
---|
| 120 | typedef VTGPROVIDER *PVTGPROVIDER;
|
---|
| 121 |
|
---|
[40569] | 122 | /**
|
---|
| 123 | * A string table string.
|
---|
| 124 | */
|
---|
| 125 | typedef struct VTGSTRING
|
---|
| 126 | {
|
---|
| 127 | /** The string space core. */
|
---|
| 128 | RTSTRSPACECORE Core;
|
---|
| 129 | /** The string table offset. */
|
---|
| 130 | uint32_t offStrTab;
|
---|
| 131 | /** The actual string. */
|
---|
| 132 | char szString[1];
|
---|
| 133 | } VTGSTRING;
|
---|
| 134 | typedef VTGSTRING *PVTGSTRING;
|
---|
[40554] | 135 |
|
---|
[40569] | 136 |
|
---|
[57353] | 137 | /*********************************************************************************************************************************
|
---|
| 138 | * Global Variables *
|
---|
| 139 | *********************************************************************************************************************************/
|
---|
[40569] | 140 | /** The string space organizing the string table strings. Each node is a VTGSTRING. */
|
---|
| 141 | static RTSTRSPACE g_StrSpace = NULL;
|
---|
| 142 | /** Used by the string table enumerator to set VTGSTRING::offStrTab. */
|
---|
| 143 | static uint32_t g_offStrTab;
|
---|
[40554] | 144 | /** List of providers created by the parser. */
|
---|
| 145 | static RTLISTANCHOR g_ProviderHead;
|
---|
[40878] | 146 | /** The number of type errors. */
|
---|
[41338] | 147 | static uint32_t g_cTypeErrors = 0;
|
---|
[40878] | 148 |
|
---|
[41338] | 149 |
|
---|
[40554] | 150 | /** @name Options
|
---|
| 151 | * @{ */
|
---|
| 152 | static enum
|
---|
| 153 | {
|
---|
| 154 | kVBoxTpGAction_Nothing,
|
---|
| 155 | kVBoxTpGAction_GenerateHeader,
|
---|
[41342] | 156 | kVBoxTpGAction_GenerateWrapperHeader,
|
---|
[40554] | 157 | kVBoxTpGAction_GenerateObject
|
---|
| 158 | } g_enmAction = kVBoxTpGAction_Nothing;
|
---|
[41338] | 159 | static uint32_t g_cBits = HC_ARCH_BITS;
|
---|
| 160 | static uint32_t g_cHostBits = HC_ARCH_BITS;
|
---|
| 161 | static uint32_t g_fTypeContext = VTG_TYPE_CTX_R0;
|
---|
[41342] | 162 | static const char *g_pszContextDefine = "IN_RING0";
|
---|
[43055] | 163 | static const char *g_pszContextDefine2 = NULL;
|
---|
[40554] | 164 | static bool g_fApplyCpp = false;
|
---|
| 165 | static uint32_t g_cVerbosity = 0;
|
---|
| 166 | static const char *g_pszOutput = NULL;
|
---|
| 167 | static const char *g_pszScript = NULL;
|
---|
| 168 | static const char *g_pszTempAsm = NULL;
|
---|
| 169 | #ifdef RT_OS_DARWIN
|
---|
| 170 | static const char *g_pszAssembler = "yasm";
|
---|
[40570] | 171 | static const char *g_pszAssemblerFmtOpt = "-f";
|
---|
[40554] | 172 | static const char g_szAssemblerFmtVal32[] = "macho32";
|
---|
| 173 | static const char g_szAssemblerFmtVal64[] = "macho64";
|
---|
[40857] | 174 | static const char g_szAssemblerOsDef[] = "RT_OS_DARWIN";
|
---|
[40554] | 175 | #elif defined(RT_OS_OS2)
|
---|
[97882] | 176 | static const char *g_pszAssembler = "nasm.exe";
|
---|
| 177 | static const char *g_pszAssemblerFmtOpt = "-f";
|
---|
[40554] | 178 | static const char g_szAssemblerFmtVal32[] = "obj";
|
---|
| 179 | static const char g_szAssemblerFmtVal64[] = "elf64";
|
---|
[40857] | 180 | static const char g_szAssemblerOsDef[] = "RT_OS_OS2";
|
---|
[40554] | 181 | #elif defined(RT_OS_WINDOWS)
|
---|
| 182 | static const char *g_pszAssembler = "yasm.exe";
|
---|
[40589] | 183 | static const char *g_pszAssemblerFmtOpt = "-f";
|
---|
[40554] | 184 | static const char g_szAssemblerFmtVal32[] = "win32";
|
---|
| 185 | static const char g_szAssemblerFmtVal64[] = "win64";
|
---|
[40857] | 186 | static const char g_szAssemblerOsDef[] = "RT_OS_WINDOWS";
|
---|
[40554] | 187 | #else
|
---|
| 188 | static const char *g_pszAssembler = "yasm";
|
---|
[40589] | 189 | static const char *g_pszAssemblerFmtOpt = "-f";
|
---|
[40554] | 190 | static const char g_szAssemblerFmtVal32[] = "elf32";
|
---|
| 191 | static const char g_szAssemblerFmtVal64[] = "elf64";
|
---|
[40857] | 192 | # ifdef RT_OS_FREEBSD
|
---|
| 193 | static const char g_szAssemblerOsDef[] = "RT_OS_FREEBSD";
|
---|
| 194 | # elif defined(RT_OS_NETBSD)
|
---|
| 195 | static const char g_szAssemblerOsDef[] = "RT_OS_NETBSD";
|
---|
| 196 | # elif defined(RT_OS_OPENBSD)
|
---|
| 197 | static const char g_szAssemblerOsDef[] = "RT_OS_OPENBSD";
|
---|
| 198 | # elif defined(RT_OS_LINUX)
|
---|
| 199 | static const char g_szAssemblerOsDef[] = "RT_OS_LINUX";
|
---|
| 200 | # elif defined(RT_OS_SOLARIS)
|
---|
| 201 | static const char g_szAssemblerOsDef[] = "RT_OS_SOLARIS";
|
---|
| 202 | # else
|
---|
| 203 | # error "Port me!"
|
---|
| 204 | # endif
|
---|
[40554] | 205 | #endif
|
---|
[41338] | 206 | static const char *g_pszAssemblerFmtVal = RT_CONCAT(g_szAssemblerFmtVal, HC_ARCH_BITS);
|
---|
[40570] | 207 | static const char *g_pszAssemblerDefOpt = "-D";
|
---|
| 208 | static const char *g_pszAssemblerIncOpt = "-I";
|
---|
| 209 | static char g_szAssemblerIncVal[RTPATH_MAX];
|
---|
| 210 | static const char *g_pszAssemblerIncVal = __FILE__ "/../../../include/";
|
---|
[40554] | 211 | static const char *g_pszAssemblerOutputOpt = "-o";
|
---|
| 212 | static unsigned g_cAssemblerOptions = 0;
|
---|
| 213 | static const char *g_apszAssemblerOptions[32];
|
---|
[40763] | 214 | static const char *g_pszProbeFnName = "SUPR0TracerFireProbe";
|
---|
[40597] | 215 | static bool g_fProbeFnImported = true;
|
---|
[40975] | 216 | static bool g_fPic = false;
|
---|
[40554] | 217 | /** @} */
|
---|
| 218 |
|
---|
| 219 |
|
---|
[40878] | 220 |
|
---|
| 221 |
|
---|
[40569] | 222 | /**
|
---|
| 223 | * Inserts a string into the string table, reusing any matching existing string
|
---|
| 224 | * if possible.
|
---|
| 225 | *
|
---|
| 226 | * @returns Read only string.
|
---|
| 227 | * @param pch The string to insert (need not be terminated).
|
---|
| 228 | * @param cch The length of the string.
|
---|
| 229 | */
|
---|
| 230 | static const char *strtabInsertN(const char *pch, size_t cch)
|
---|
| 231 | {
|
---|
| 232 | PVTGSTRING pStr = (PVTGSTRING)RTStrSpaceGetN(&g_StrSpace, pch, cch);
|
---|
| 233 | if (pStr)
|
---|
| 234 | return pStr->szString;
|
---|
| 235 |
|
---|
| 236 | /*
|
---|
| 237 | * Create a new entry.
|
---|
| 238 | */
|
---|
[73097] | 239 | pStr = (PVTGSTRING)RTMemAlloc(RT_UOFFSETOF_DYN(VTGSTRING, szString[cch + 1]));
|
---|
[40569] | 240 | if (!pStr)
|
---|
| 241 | return NULL;
|
---|
| 242 |
|
---|
| 243 | pStr->Core.pszString = pStr->szString;
|
---|
| 244 | memcpy(pStr->szString, pch, cch);
|
---|
| 245 | pStr->szString[cch] = '\0';
|
---|
| 246 | pStr->offStrTab = UINT32_MAX;
|
---|
| 247 |
|
---|
| 248 | bool fRc = RTStrSpaceInsert(&g_StrSpace, &pStr->Core);
|
---|
| 249 | Assert(fRc); NOREF(fRc);
|
---|
| 250 | return pStr->szString;
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 |
|
---|
[40570] | 254 | /**
|
---|
| 255 | * Retrieves the string table offset of the given string table string.
|
---|
| 256 | *
|
---|
| 257 | * @returns String table offset.
|
---|
| 258 | * @param pszStrTabString The string table string.
|
---|
| 259 | */
|
---|
| 260 | static uint32_t strtabGetOff(const char *pszStrTabString)
|
---|
| 261 | {
|
---|
| 262 | PVTGSTRING pStr = RT_FROM_MEMBER(pszStrTabString, VTGSTRING, szString[0]);
|
---|
| 263 | Assert(pStr->Core.pszString == pszStrTabString);
|
---|
| 264 | return pStr->offStrTab;
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 |
|
---|
[40572] | 268 | /**
|
---|
| 269 | * Invokes the assembler.
|
---|
| 270 | *
|
---|
| 271 | * @returns Exit code.
|
---|
| 272 | * @param pszOutput The output file.
|
---|
| 273 | * @param pszTempAsm The source file.
|
---|
| 274 | */
|
---|
[40554] | 275 | static RTEXITCODE generateInvokeAssembler(const char *pszOutput, const char *pszTempAsm)
|
---|
| 276 | {
|
---|
[40570] | 277 | const char *apszArgs[64];
|
---|
| 278 | unsigned iArg = 0;
|
---|
| 279 |
|
---|
| 280 | apszArgs[iArg++] = g_pszAssembler;
|
---|
| 281 | apszArgs[iArg++] = g_pszAssemblerFmtOpt;
|
---|
| 282 | apszArgs[iArg++] = g_pszAssemblerFmtVal;
|
---|
| 283 | apszArgs[iArg++] = g_pszAssemblerDefOpt;
|
---|
| 284 | if (!strcmp(g_pszAssemblerFmtVal, "macho32") || !strcmp(g_pszAssemblerFmtVal, "macho64"))
|
---|
| 285 | apszArgs[iArg++] = "ASM_FORMAT_MACHO";
|
---|
| 286 | else if (!strcmp(g_pszAssemblerFmtVal, "obj") || !strcmp(g_pszAssemblerFmtVal, "omf"))
|
---|
| 287 | apszArgs[iArg++] = "ASM_FORMAT_OMF";
|
---|
| 288 | else if ( !strcmp(g_pszAssemblerFmtVal, "win32")
|
---|
| 289 | || !strcmp(g_pszAssemblerFmtVal, "win64")
|
---|
| 290 | || !strcmp(g_pszAssemblerFmtVal, "pe32")
|
---|
| 291 | || !strcmp(g_pszAssemblerFmtVal, "pe64")
|
---|
| 292 | || !strcmp(g_pszAssemblerFmtVal, "pe") )
|
---|
| 293 | apszArgs[iArg++] = "ASM_FORMAT_PE";
|
---|
| 294 | else if ( !strcmp(g_pszAssemblerFmtVal, "elf32")
|
---|
| 295 | || !strcmp(g_pszAssemblerFmtVal, "elf64")
|
---|
| 296 | || !strcmp(g_pszAssemblerFmtVal, "elf"))
|
---|
| 297 | apszArgs[iArg++] = "ASM_FORMAT_ELF";
|
---|
| 298 | else
|
---|
| 299 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "Unknown assembler format '%s'", g_pszAssemblerFmtVal);
|
---|
| 300 | apszArgs[iArg++] = g_pszAssemblerDefOpt;
|
---|
| 301 | if (g_cBits == 32)
|
---|
| 302 | apszArgs[iArg++] = "ARCH_BITS=32";
|
---|
| 303 | else
|
---|
| 304 | apszArgs[iArg++] = "ARCH_BITS=64";
|
---|
| 305 | apszArgs[iArg++] = g_pszAssemblerDefOpt;
|
---|
[41338] | 306 | if (g_cHostBits == 32)
|
---|
| 307 | apszArgs[iArg++] = "HC_ARCH_BITS=32";
|
---|
| 308 | else
|
---|
| 309 | apszArgs[iArg++] = "HC_ARCH_BITS=64";
|
---|
| 310 | apszArgs[iArg++] = g_pszAssemblerDefOpt;
|
---|
[40570] | 311 | if (g_cBits == 32)
|
---|
| 312 | apszArgs[iArg++] = "RT_ARCH_X86";
|
---|
| 313 | else
|
---|
| 314 | apszArgs[iArg++] = "RT_ARCH_AMD64";
|
---|
[41338] | 315 | apszArgs[iArg++] = g_pszAssemblerDefOpt;
|
---|
[41342] | 316 | apszArgs[iArg++] = g_pszContextDefine;
|
---|
[43055] | 317 | if (g_pszContextDefine2)
|
---|
| 318 | {
|
---|
| 319 | apszArgs[iArg++] = g_pszAssemblerDefOpt;
|
---|
| 320 | apszArgs[iArg++] = g_pszContextDefine2;
|
---|
| 321 | }
|
---|
[40857] | 322 | if (g_szAssemblerOsDef[0])
|
---|
| 323 | {
|
---|
| 324 | apszArgs[iArg++] = g_pszAssemblerDefOpt;
|
---|
| 325 | apszArgs[iArg++] = g_szAssemblerOsDef;
|
---|
| 326 | }
|
---|
[40570] | 327 | apszArgs[iArg++] = g_pszAssemblerIncOpt;
|
---|
| 328 | apszArgs[iArg++] = g_pszAssemblerIncVal;
|
---|
| 329 | apszArgs[iArg++] = g_pszAssemblerOutputOpt;
|
---|
| 330 | apszArgs[iArg++] = pszOutput;
|
---|
| 331 | for (unsigned i = 0; i < g_cAssemblerOptions; i++)
|
---|
| 332 | apszArgs[iArg++] = g_apszAssemblerOptions[i];
|
---|
| 333 | apszArgs[iArg++] = pszTempAsm;
|
---|
| 334 | apszArgs[iArg] = NULL;
|
---|
[43055] | 335 | Assert(iArg <= RT_ELEMENTS(apszArgs));
|
---|
[40570] | 336 |
|
---|
| 337 | if (g_cVerbosity > 1)
|
---|
| 338 | {
|
---|
| 339 | RTMsgInfo("Starting assmbler '%s' with arguments:\n", g_pszAssembler);
|
---|
| 340 | for (unsigned i = 0; i < iArg; i++)
|
---|
| 341 | RTMsgInfo(" #%02u: '%s'\n", i, apszArgs[i]);
|
---|
| 342 | }
|
---|
| 343 |
|
---|
| 344 | RTPROCESS hProc;
|
---|
| 345 | int rc = RTProcCreate(apszArgs[0], apszArgs, RTENV_DEFAULT, RTPROC_FLAGS_SEARCH_PATH, &hProc);
|
---|
| 346 | if (RT_FAILURE(rc))
|
---|
[40826] | 347 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to start '%s' (assembler): %Rrc", apszArgs[0], rc);
|
---|
[40570] | 348 |
|
---|
| 349 | RTPROCSTATUS Status;
|
---|
| 350 | rc = RTProcWait(hProc, RTPROCWAIT_FLAGS_BLOCK, &Status);
|
---|
| 351 | if (RT_FAILURE(rc))
|
---|
| 352 | {
|
---|
| 353 | RTProcTerminate(hProc);
|
---|
| 354 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTProcWait failed: %Rrc", rc);
|
---|
| 355 | }
|
---|
| 356 | if (Status.enmReason == RTPROCEXITREASON_SIGNAL)
|
---|
| 357 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "The assembler failed: signal %d", Status.iStatus);
|
---|
[40572] | 358 | if (Status.enmReason != RTPROCEXITREASON_NORMAL)
|
---|
[40570] | 359 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "The assembler failed: abend");
|
---|
[40572] | 360 | if (Status.iStatus != 0)
|
---|
| 361 | return RTMsgErrorExit((RTEXITCODE)Status.iStatus, "The assembler failed: exit code %d", Status.iStatus);
|
---|
[40570] | 362 |
|
---|
| 363 | return RTEXITCODE_SUCCESS;
|
---|
[40554] | 364 | }
|
---|
| 365 |
|
---|
| 366 |
|
---|
[40572] | 367 | /**
|
---|
| 368 | * Worker that does the boring bits when generating a file.
|
---|
| 369 | *
|
---|
| 370 | * @returns Exit code.
|
---|
| 371 | * @param pszOutput The name of the output file.
|
---|
| 372 | * @param pszWhat What kind of file it is.
|
---|
| 373 | * @param pfnGenerator The callback function that provides the contents
|
---|
| 374 | * of the file.
|
---|
| 375 | */
|
---|
[40554] | 376 | static RTEXITCODE generateFile(const char *pszOutput, const char *pszWhat,
|
---|
| 377 | RTEXITCODE (*pfnGenerator)(PSCMSTREAM))
|
---|
| 378 | {
|
---|
| 379 | SCMSTREAM Strm;
|
---|
| 380 | int rc = ScmStreamInitForWriting(&Strm, NULL);
|
---|
[40549] | 381 | if (RT_FAILURE(rc))
|
---|
[40554] | 382 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "ScmStreamInitForWriting returned %Rrc when generating the %s file",
|
---|
| 383 | rc, pszWhat);
|
---|
[40549] | 384 |
|
---|
[40554] | 385 | RTEXITCODE rcExit = pfnGenerator(&Strm);
|
---|
| 386 | if (RT_FAILURE(ScmStreamGetStatus(&Strm)))
|
---|
| 387 | rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Stream error %Rrc generating the %s file",
|
---|
| 388 | ScmStreamGetStatus(&Strm), pszWhat);
|
---|
| 389 | if (rcExit == RTEXITCODE_SUCCESS)
|
---|
| 390 | {
|
---|
| 391 | rc = ScmStreamWriteToFile(&Strm, "%s", pszOutput);
|
---|
| 392 | if (RT_FAILURE(rc))
|
---|
| 393 | rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "ScmStreamWriteToFile returned %Rrc when writing '%s' (%s)",
|
---|
| 394 | rc, pszOutput, pszWhat);
|
---|
| 395 | if (rcExit == RTEXITCODE_SUCCESS)
|
---|
| 396 | {
|
---|
| 397 | if (g_cVerbosity > 0)
|
---|
| 398 | RTMsgInfo("Successfully generated '%s'.", pszOutput);
|
---|
| 399 | if (g_cVerbosity > 1)
|
---|
| 400 | {
|
---|
| 401 | RTMsgInfo("================ %s - start ================", pszWhat);
|
---|
| 402 | ScmStreamRewindForReading(&Strm);
|
---|
| 403 | const char *pszLine;
|
---|
| 404 | size_t cchLine;
|
---|
| 405 | SCMEOL enmEol;
|
---|
| 406 | while ((pszLine = ScmStreamGetLine(&Strm, &cchLine, &enmEol)) != NULL)
|
---|
| 407 | RTPrintf("%.*s\n", cchLine, pszLine);
|
---|
| 408 | RTMsgInfo("================ %s - end ================", pszWhat);
|
---|
| 409 | }
|
---|
| 410 | }
|
---|
| 411 | }
|
---|
| 412 | ScmStreamDelete(&Strm);
|
---|
| 413 | return rcExit;
|
---|
| 414 | }
|
---|
| 415 |
|
---|
[40572] | 416 |
|
---|
| 417 | /**
|
---|
[40569] | 418 | * @callback_method_impl{FNRTSTRSPACECALLBACK, Writes the string table strings.}
|
---|
| 419 | */
|
---|
| 420 | static DECLCALLBACK(int) generateAssemblyStrTabCallback(PRTSTRSPACECORE pStr, void *pvUser)
|
---|
| 421 | {
|
---|
| 422 | PVTGSTRING pVtgStr = (PVTGSTRING)pStr;
|
---|
| 423 | PSCMSTREAM pStrm = (PSCMSTREAM)pvUser;
|
---|
| 424 |
|
---|
| 425 | pVtgStr->offStrTab = g_offStrTab;
|
---|
[40826] | 426 | g_offStrTab += (uint32_t)pVtgStr->Core.cchString + 1;
|
---|
[40569] | 427 |
|
---|
| 428 | ScmStreamPrintf(pStrm,
|
---|
| 429 | " db '%s', 0 ; off=%u len=%zu\n",
|
---|
| 430 | pVtgStr->szString, pVtgStr->offStrTab, pVtgStr->Core.cchString);
|
---|
| 431 | return VINF_SUCCESS;
|
---|
| 432 | }
|
---|
| 433 |
|
---|
| 434 |
|
---|
[40572] | 435 | /**
|
---|
| 436 | * Generate assembly source that can be turned into an object file.
|
---|
| 437 | *
|
---|
| 438 | * (This is a generateFile callback.)
|
---|
| 439 | *
|
---|
| 440 | * @returns Exit code.
|
---|
| 441 | * @param pStrm The output stream.
|
---|
| 442 | */
|
---|
[40554] | 443 | static RTEXITCODE generateAssembly(PSCMSTREAM pStrm)
|
---|
| 444 | {
|
---|
[40572] | 445 | PVTGPROVIDER pProvider;
|
---|
| 446 | PVTGPROBE pProbe;
|
---|
| 447 | PVTGARG pArg;
|
---|
| 448 |
|
---|
| 449 |
|
---|
[40554] | 450 | if (g_cVerbosity > 0)
|
---|
| 451 | RTMsgInfo("Generating assembly code...");
|
---|
| 452 |
|
---|
[40558] | 453 | /*
|
---|
| 454 | * Write the file header.
|
---|
| 455 | */
|
---|
| 456 | ScmStreamPrintf(pStrm,
|
---|
| 457 | "; $Id: VBoxTpG.cpp 104620 2024-05-14 06:56:35Z vboxsync $ \n"
|
---|
| 458 | ";; @file\n"
|
---|
| 459 | "; Automatically generated from %s. Do NOT edit!\n"
|
---|
| 460 | ";\n"
|
---|
| 461 | "\n"
|
---|
[40570] | 462 | "%%include \"iprt/asmdefs.mac\"\n"
|
---|
[40558] | 463 | "\n"
|
---|
[40570] | 464 | "\n"
|
---|
| 465 | ";"
|
---|
[40589] | 466 | "; We put all the data in a dedicated section / segment.\n"
|
---|
[40570] | 467 | ";\n"
|
---|
[40589] | 468 | "; In order to find the probe location specifiers, we do the necessary\n"
|
---|
| 469 | "; trickery here, ASSUMING that this object comes in first in the link\n"
|
---|
| 470 | "; editing process.\n"
|
---|
| 471 | ";\n"
|
---|
[40570] | 472 | "%%ifdef ASM_FORMAT_OMF\n"
|
---|
[40594] | 473 | " %%macro VTG_GLOBAL 2\n"
|
---|
| 474 | " global NAME(%%1)\n"
|
---|
| 475 | " NAME(%%1):\n"
|
---|
| 476 | " %%endmacro\n"
|
---|
[41117] | 477 | " segment VTG.Obj public CLASS=VTG align=4096 use32\n"
|
---|
[40594] | 478 | "\n"
|
---|
[40570] | 479 | "%%elifdef ASM_FORMAT_MACHO\n"
|
---|
[40594] | 480 | " %%macro VTG_GLOBAL 2\n"
|
---|
| 481 | " global NAME(%%1)\n"
|
---|
| 482 | " NAME(%%1):\n"
|
---|
| 483 | " %%endmacro\n"
|
---|
[43055] | 484 | " %%ifdef IN_RING3\n"
|
---|
| 485 | " %%define VTG_NEW_MACHO_LINKER\n"
|
---|
| 486 | " %%elif ARCH_BITS == 64\n"
|
---|
| 487 | " %%define VTG_NEW_MACHO_LINKER\n"
|
---|
| 488 | " %%elifdef IN_RING0_AGNOSTIC\n"
|
---|
| 489 | " %%define VTG_NEW_MACHO_LINKER\n"
|
---|
| 490 | " %%endif\n"
|
---|
| 491 | " %%ifdef VTG_NEW_MACHO_LINKER\n"
|
---|
| 492 | " ; Section order hack!\n"
|
---|
| 493 | " ; With the ld64-97.17 linker there was a problem with it determining the section\n"
|
---|
| 494 | " ; order based on symbol references. The references to the start and end of the\n"
|
---|
| 495 | " ; __VTGPrLc section forced it in front of __VTGObj, we want __VTGObj first.\n"
|
---|
| 496 | " extern section$start$__VTG$__VTGObj\n"
|
---|
| 497 | " extern section$end$__VTG$__VTGObj\n"
|
---|
| 498 | " %%else\n"
|
---|
| 499 | " ; Creating 32-bit kext of the type MH_OBJECT. No fancy section end/start symbols handy.\n"
|
---|
| 500 | " [section __VTG __VTGObj align=16]\n"
|
---|
| 501 | "VTG_GLOBAL g_aVTGObj_LinkerPleaseNoticeMe, data\n"
|
---|
| 502 | " [section __VTG __VTGPrLc.Begin align=16]\n"
|
---|
[47518] | 503 | " dq 0, 0 ; Paranoia, related to the fudge below.\n"
|
---|
[43055] | 504 | "VTG_GLOBAL g_aVTGPrLc, data\n"
|
---|
| 505 | " [section __VTG __VTGPrLc align=16]\n"
|
---|
| 506 | "VTG_GLOBAL g_aVTGPrLc_LinkerPleaseNoticeMe, data\n"
|
---|
| 507 | " [section __VTG __VTGPrLc.End align=16]\n"
|
---|
| 508 | "VTG_GLOBAL g_aVTGPrLc_End, data\n"
|
---|
[47518] | 509 | " dq 0, 0 ; Fudge to work around unidentified linker where it would otherwise generate\n"
|
---|
| 510 | " ; a fix up of the first dword in __VTGPrLc.Begin despite the fact that it were\n"
|
---|
| 511 | " ; an empty section with nothing whatsoever to fix up.\n"
|
---|
[43055] | 512 | " %%endif\n"
|
---|
| 513 | " [section __VTG __VTGObj]\n"
|
---|
[40594] | 514 | "\n"
|
---|
[40570] | 515 | "%%elifdef ASM_FORMAT_PE\n"
|
---|
[40594] | 516 | " %%macro VTG_GLOBAL 2\n"
|
---|
| 517 | " global NAME(%%1)\n"
|
---|
| 518 | " NAME(%%1):\n"
|
---|
| 519 | " %%endmacro\n"
|
---|
[40826] | 520 | " [section VTGPrLc.Begin data align=64]\n"
|
---|
[40851] | 521 | /*" times 16 db 0xcc\n"*/
|
---|
[40826] | 522 | "VTG_GLOBAL g_aVTGPrLc, data\n"
|
---|
| 523 | " [section VTGPrLc.Data data align=4]\n"
|
---|
| 524 | " [section VTGPrLc.End data align=4]\n"
|
---|
| 525 | "VTG_GLOBAL g_aVTGPrLc_End, data\n"
|
---|
[40851] | 526 | /*" times 16 db 0xcc\n"*/
|
---|
[40826] | 527 | " [section VTGObj data align=32]\n"
|
---|
[40589] | 528 | "\n"
|
---|
[40570] | 529 | "%%elifdef ASM_FORMAT_ELF\n"
|
---|
[40594] | 530 | " %%macro VTG_GLOBAL 2\n"
|
---|
| 531 | " global NAME(%%1):%%2 hidden\n"
|
---|
| 532 | " NAME(%%1):\n"
|
---|
| 533 | " %%endmacro\n"
|
---|
[41117] | 534 | " [section .VTGData progbits alloc noexec write align=4096]\n"
|
---|
| 535 | " [section .VTGPrLc.Begin progbits alloc noexec write align=32]\n"
|
---|
| 536 | " dd 0,0,0,0, 0,0,0,0\n"
|
---|
[40594] | 537 | "VTG_GLOBAL g_aVTGPrLc, data\n"
|
---|
[40851] | 538 | " [section .VTGPrLc progbits alloc noexec write align=1]\n"
|
---|
| 539 | " [section .VTGPrLc.End progbits alloc noexec write align=1]\n"
|
---|
[40594] | 540 | "VTG_GLOBAL g_aVTGPrLc_End, data\n"
|
---|
[41117] | 541 | " dd 0,0,0,0, 0,0,0,0\n"
|
---|
[41338] | 542 | " [section .VTGData]\n"
|
---|
[40594] | 543 | "\n"
|
---|
[40570] | 544 | "%%else\n"
|
---|
| 545 | " %%error \"ASM_FORMAT_XXX is not defined\"\n"
|
---|
| 546 | "%%endif\n"
|
---|
| 547 | "\n"
|
---|
[40594] | 548 | "\n"
|
---|
| 549 | "VTG_GLOBAL g_VTGObjHeader, data\n"
|
---|
| 550 | " ;0 1 2 3\n"
|
---|
| 551 | " ;012345678901234567890123456789012\n"
|
---|
[58976] | 552 | " db 'VTG Object Header v1.7', 0, 0\n"
|
---|
[40594] | 553 | " dd %u\n"
|
---|
[41117] | 554 | " dd NAME(g_acVTGProbeEnabled_End) - NAME(g_VTGObjHeader)\n"
|
---|
| 555 | " dd NAME(g_achVTGStringTable) - NAME(g_VTGObjHeader)\n"
|
---|
| 556 | " dd NAME(g_achVTGStringTable_End) - NAME(g_achVTGStringTable)\n"
|
---|
| 557 | " dd NAME(g_aVTGArgLists) - NAME(g_VTGObjHeader)\n"
|
---|
| 558 | " dd NAME(g_aVTGArgLists_End) - NAME(g_aVTGArgLists)\n"
|
---|
| 559 | " dd NAME(g_aVTGProbes) - NAME(g_VTGObjHeader)\n"
|
---|
| 560 | " dd NAME(g_aVTGProbes_End) - NAME(g_aVTGProbes)\n"
|
---|
| 561 | " dd NAME(g_aVTGProviders) - NAME(g_VTGObjHeader)\n"
|
---|
| 562 | " dd NAME(g_aVTGProviders_End) - NAME(g_aVTGProviders)\n"
|
---|
| 563 | " dd NAME(g_acVTGProbeEnabled) - NAME(g_VTGObjHeader)\n"
|
---|
| 564 | " dd NAME(g_acVTGProbeEnabled_End) - NAME(g_acVTGProbeEnabled)\n"
|
---|
[40594] | 565 | " dd 0\n"
|
---|
[41117] | 566 | " dd 0\n"
|
---|
[43055] | 567 | "%%ifdef VTG_NEW_MACHO_LINKER\n"
|
---|
| 568 | " extern section$start$__VTG$__VTGPrLc\n"
|
---|
[40857] | 569 | " RTCCPTR_DEF section$start$__VTG$__VTGPrLc\n"
|
---|
[41117] | 570 | " %%if ARCH_BITS == 32\n"
|
---|
| 571 | " dd 0\n"
|
---|
| 572 | " %%endif\n"
|
---|
[43055] | 573 | " extern section$end$__VTG$__VTGPrLc\n"
|
---|
[40857] | 574 | " RTCCPTR_DEF section$end$__VTG$__VTGPrLc\n"
|
---|
[41117] | 575 | " %%if ARCH_BITS == 32\n"
|
---|
| 576 | " dd 0\n"
|
---|
| 577 | " %%endif\n"
|
---|
[40857] | 578 | "%%else\n"
|
---|
[40594] | 579 | " RTCCPTR_DEF NAME(g_aVTGPrLc)\n"
|
---|
[41117] | 580 | " %%if ARCH_BITS == 32\n"
|
---|
| 581 | " dd 0\n"
|
---|
| 582 | " %%endif\n"
|
---|
| 583 | " RTCCPTR_DEF NAME(g_aVTGPrLc_End)\n"
|
---|
| 584 | " %%if ARCH_BITS == 32\n"
|
---|
| 585 | " dd 0\n"
|
---|
| 586 | " %%endif\n"
|
---|
[40857] | 587 | "%%endif\n"
|
---|
[40558] | 588 | ,
|
---|
[40594] | 589 | g_pszScript, g_cBits);
|
---|
[41117] | 590 | RTUUID Uuid;
|
---|
| 591 | int rc = RTUuidCreate(&Uuid);
|
---|
| 592 | if (RT_FAILURE(rc))
|
---|
| 593 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTUuidCreate failed: %Rrc", rc);
|
---|
[40569] | 594 | ScmStreamPrintf(pStrm,
|
---|
[41117] | 595 | " dd 0%08xh, 0%08xh, 0%08xh, 0%08xh\n"
|
---|
[43055] | 596 | "%%ifdef VTG_NEW_MACHO_LINKER\n"
|
---|
[41311] | 597 | " RTCCPTR_DEF section$start$__VTG$__VTGObj\n"
|
---|
| 598 | " %%if ARCH_BITS == 32\n"
|
---|
| 599 | " dd 0\n"
|
---|
| 600 | " %%endif\n"
|
---|
| 601 | "%%else\n"
|
---|
| 602 | " dd 0, 0\n"
|
---|
| 603 | "%%endif\n"
|
---|
| 604 | " dd 0, 0\n"
|
---|
[41117] | 605 | , Uuid.au32[0], Uuid.au32[1], Uuid.au32[2], Uuid.au32[3]);
|
---|
[40570] | 606 |
|
---|
| 607 | /*
|
---|
| 608 | * Dump the string table before we start using the strings.
|
---|
| 609 | */
|
---|
| 610 | ScmStreamPrintf(pStrm,
|
---|
[40572] | 611 | "\n"
|
---|
[40570] | 612 | ";\n"
|
---|
[40569] | 613 | "; The string table.\n"
|
---|
| 614 | ";\n"
|
---|
[40594] | 615 | "VTG_GLOBAL g_achVTGStringTable, data\n");
|
---|
[40569] | 616 | g_offStrTab = 0;
|
---|
| 617 | RTStrSpaceEnumerate(&g_StrSpace, generateAssemblyStrTabCallback, pStrm);
|
---|
| 618 | ScmStreamPrintf(pStrm,
|
---|
[40594] | 619 | "VTG_GLOBAL g_achVTGStringTable_End, data\n");
|
---|
[40569] | 620 |
|
---|
| 621 | /*
|
---|
[40570] | 622 | * Write out the argument lists before we use them.
|
---|
[40558] | 623 | */
|
---|
| 624 | ScmStreamPrintf(pStrm,
|
---|
[40572] | 625 | "\n"
|
---|
[40558] | 626 | ";\n"
|
---|
[40570] | 627 | "; The argument lists.\n"
|
---|
[40558] | 628 | ";\n"
|
---|
[41117] | 629 | "ALIGNDATA(16)\n"
|
---|
[40594] | 630 | "VTG_GLOBAL g_aVTGArgLists, data\n");
|
---|
[40570] | 631 | uint32_t off = 0;
|
---|
[40572] | 632 | RTListForEach(&g_ProviderHead, pProvider, VTGPROVIDER, ListEntry)
|
---|
[40558] | 633 | {
|
---|
[40572] | 634 | RTListForEach(&pProvider->ProbeHead, pProbe, VTGPROBE, ListEntry)
|
---|
[40558] | 635 | {
|
---|
[40570] | 636 | if (pProbe->offArgList != UINT32_MAX)
|
---|
| 637 | continue;
|
---|
| 638 |
|
---|
| 639 | /* Write it. */
|
---|
| 640 | pProbe->offArgList = off;
|
---|
[40558] | 641 | ScmStreamPrintf(pStrm,
|
---|
[40570] | 642 | " ; off=%u\n"
|
---|
[40892] | 643 | " db %2u ; Argument count\n"
|
---|
| 644 | " db %u ; fHaveLargeArgs\n"
|
---|
| 645 | " db 0, 0 ; Reserved\n"
|
---|
[40884] | 646 | , off, pProbe->cArgs, (int)pProbe->fHaveLargeArgs);
|
---|
[40570] | 647 | off += 4;
|
---|
| 648 | RTListForEach(&pProbe->ArgHead, pArg, VTGARG, ListEntry)
|
---|
| 649 | {
|
---|
| 650 | ScmStreamPrintf(pStrm,
|
---|
[40892] | 651 | " dd %8u ; type '%s' (name '%s')\n"
|
---|
[40878] | 652 | " dd 0%08xh ; type flags\n",
|
---|
[41338] | 653 | strtabGetOff(pArg->pszTracerType), pArg->pszTracerType, pArg->pszName,
|
---|
[40878] | 654 | pArg->fType);
|
---|
[40570] | 655 | off += 8;
|
---|
| 656 | }
|
---|
| 657 |
|
---|
| 658 | /* Look for matching argument lists (lazy bird walks the whole list). */
|
---|
| 659 | PVTGPROVIDER pProv2;
|
---|
| 660 | RTListForEach(&g_ProviderHead, pProv2, VTGPROVIDER, ListEntry)
|
---|
| 661 | {
|
---|
| 662 | PVTGPROBE pProbe2;
|
---|
[40572] | 663 | RTListForEach(&pProvider->ProbeHead, pProbe2, VTGPROBE, ListEntry)
|
---|
[40570] | 664 | {
|
---|
| 665 | if (pProbe2->offArgList != UINT32_MAX)
|
---|
| 666 | continue;
|
---|
| 667 | if (pProbe2->cArgs != pProbe->cArgs)
|
---|
| 668 | continue;
|
---|
| 669 |
|
---|
| 670 | PVTGARG pArg2;
|
---|
| 671 | pArg = RTListNodeGetNext(&pProbe->ArgHead, VTGARG, ListEntry);
|
---|
| 672 | pArg2 = RTListNodeGetNext(&pProbe2->ArgHead, VTGARG, ListEntry);
|
---|
| 673 | int32_t cArgs = pProbe->cArgs;
|
---|
| 674 | while ( cArgs-- > 0
|
---|
[41338] | 675 | && pArg2->pszTracerType == pArg->pszTracerType
|
---|
| 676 | && pArg2->fType == pArg->fType)
|
---|
[40570] | 677 | {
|
---|
| 678 | pArg = RTListNodeGetNext(&pArg->ListEntry, VTGARG, ListEntry);
|
---|
| 679 | pArg2 = RTListNodeGetNext(&pArg2->ListEntry, VTGARG, ListEntry);
|
---|
| 680 | }
|
---|
| 681 | if (cArgs >= 0)
|
---|
| 682 | continue;
|
---|
| 683 | pProbe2->offArgList = pProbe->offArgList;
|
---|
| 684 | }
|
---|
| 685 | }
|
---|
[40558] | 686 | }
|
---|
| 687 | }
|
---|
[40570] | 688 | ScmStreamPrintf(pStrm,
|
---|
[40594] | 689 | "VTG_GLOBAL g_aVTGArgLists_End, data\n");
|
---|
[40558] | 690 |
|
---|
[40570] | 691 |
|
---|
[40558] | 692 | /*
|
---|
[40572] | 693 | * Probe definitions.
|
---|
[40558] | 694 | */
|
---|
| 695 | ScmStreamPrintf(pStrm,
|
---|
| 696 | "\n"
|
---|
| 697 | ";\n"
|
---|
[40570] | 698 | "; Prob definitions.\n"
|
---|
[40558] | 699 | ";\n"
|
---|
[41117] | 700 | "ALIGNDATA(16)\n"
|
---|
[40594] | 701 | "VTG_GLOBAL g_aVTGProbes, data\n"
|
---|
[40558] | 702 | "\n");
|
---|
[40572] | 703 | uint32_t iProvider = 0;
|
---|
[40570] | 704 | uint32_t iProbe = 0;
|
---|
[40572] | 705 | RTListForEach(&g_ProviderHead, pProvider, VTGPROVIDER, ListEntry)
|
---|
[40558] | 706 | {
|
---|
[40572] | 707 | pProvider->iFirstProbe = iProbe;
|
---|
| 708 | RTListForEach(&pProvider->ProbeHead, pProbe, VTGPROBE, ListEntry)
|
---|
[40558] | 709 | {
|
---|
[40570] | 710 | ScmStreamPrintf(pStrm,
|
---|
[40594] | 711 | "VTG_GLOBAL g_VTGProbeData_%s_%s, data ; idx=#%4u\n"
|
---|
[41117] | 712 | " dd %6u ; offName\n"
|
---|
| 713 | " dd %6u ; offArgList\n"
|
---|
| 714 | " dw (NAME(g_cVTGProbeEnabled_%s_%s) - NAME(g_acVTGProbeEnabled)) / 4 ; idxEnabled\n"
|
---|
| 715 | " dw %6u ; idxProvider\n"
|
---|
| 716 | " dd NAME(g_VTGObjHeader) - NAME(g_VTGProbeData_%s_%s) ; offObjHdr\n"
|
---|
[40570] | 717 | ,
|
---|
[40619] | 718 | pProvider->pszName, pProbe->pszMangledName, iProbe,
|
---|
| 719 | strtabGetOff(pProbe->pszUnmangledName),
|
---|
[40570] | 720 | pProbe->offArgList,
|
---|
[40619] | 721 | pProvider->pszName, pProbe->pszMangledName,
|
---|
[40892] | 722 | iProvider,
|
---|
| 723 | pProvider->pszName, pProbe->pszMangledName
|
---|
| 724 | );
|
---|
[40570] | 725 | pProbe->iProbe = iProbe;
|
---|
| 726 | iProbe++;
|
---|
[40558] | 727 | }
|
---|
[40572] | 728 | pProvider->cProbes = iProbe - pProvider->iFirstProbe;
|
---|
| 729 | iProvider++;
|
---|
[40558] | 730 | }
|
---|
[40594] | 731 | ScmStreamPrintf(pStrm, "VTG_GLOBAL g_aVTGProbes_End, data\n");
|
---|
[40558] | 732 |
|
---|
[40570] | 733 | /*
|
---|
[41117] | 734 | * The provider data.
|
---|
[40570] | 735 | */
|
---|
| 736 | ScmStreamPrintf(pStrm,
|
---|
| 737 | "\n"
|
---|
| 738 | ";\n"
|
---|
| 739 | "; Provider data.\n"
|
---|
| 740 | ";\n"
|
---|
[41117] | 741 | "ALIGNDATA(16)\n"
|
---|
[40594] | 742 | "VTG_GLOBAL g_aVTGProviders, data\n");
|
---|
[40572] | 743 | iProvider = 0;
|
---|
| 744 | RTListForEach(&g_ProviderHead, pProvider, VTGPROVIDER, ListEntry)
|
---|
[40570] | 745 | {
|
---|
| 746 | ScmStreamPrintf(pStrm,
|
---|
[40572] | 747 | " ; idx=#%4u - %s\n"
|
---|
[40570] | 748 | " dd %6u ; name\n"
|
---|
[40572] | 749 | " dw %6u ; index of first probe\n"
|
---|
| 750 | " dw %6u ; count of probes\n"
|
---|
| 751 | " db %d, %d, %d ; AttrSelf\n"
|
---|
| 752 | " db %d, %d, %d ; AttrModules\n"
|
---|
| 753 | " db %d, %d, %d ; AttrFunctions\n"
|
---|
| 754 | " db %d, %d, %d ; AttrName\n"
|
---|
| 755 | " db %d, %d, %d ; AttrArguments\n"
|
---|
| 756 | " db 0 ; reserved\n"
|
---|
[58920] | 757 | "VTG_GLOBAL g_cVTGProviderProbesEnabled_%s, data\n"
|
---|
| 758 | " dd 0\n"
|
---|
[58976] | 759 | "VTG_GLOBAL g_cVTGProviderSettingsSeqNo_%s, data\n"
|
---|
| 760 | " dd 0\n"
|
---|
[40570] | 761 | ,
|
---|
[40572] | 762 | iProvider, pProvider->pszName,
|
---|
| 763 | strtabGetOff(pProvider->pszName),
|
---|
| 764 | pProvider->iFirstProbe,
|
---|
| 765 | pProvider->cProbes,
|
---|
| 766 | pProvider->AttrSelf.enmCode, pProvider->AttrSelf.enmData, pProvider->AttrSelf.enmDataDep,
|
---|
| 767 | pProvider->AttrModules.enmCode, pProvider->AttrModules.enmData, pProvider->AttrModules.enmDataDep,
|
---|
| 768 | pProvider->AttrFunctions.enmCode, pProvider->AttrFunctions.enmData, pProvider->AttrFunctions.enmDataDep,
|
---|
| 769 | pProvider->AttrName.enmCode, pProvider->AttrName.enmData, pProvider->AttrName.enmDataDep,
|
---|
[58920] | 770 | pProvider->AttrArguments.enmCode, pProvider->AttrArguments.enmData, pProvider->AttrArguments.enmDataDep,
|
---|
[58976] | 771 | pProvider->pszName,
|
---|
[58920] | 772 | pProvider->pszName);
|
---|
[40570] | 773 | iProvider++;
|
---|
| 774 | }
|
---|
[40594] | 775 | ScmStreamPrintf(pStrm, "VTG_GLOBAL g_aVTGProviders_End, data\n");
|
---|
[40570] | 776 |
|
---|
| 777 | /*
|
---|
[41117] | 778 | * Declare the probe enable flags.
|
---|
| 779 | *
|
---|
| 780 | * These must be placed at the end so they'll end up adjacent to the probe
|
---|
| 781 | * locations. This is important for reducing the amount of memory we need
|
---|
| 782 | * to lock down for user mode modules.
|
---|
| 783 | */
|
---|
| 784 | ScmStreamPrintf(pStrm,
|
---|
| 785 | ";\n"
|
---|
| 786 | "; Probe enabled flags.\n"
|
---|
| 787 | ";\n"
|
---|
| 788 | "ALIGNDATA(16)\n"
|
---|
| 789 | "VTG_GLOBAL g_acVTGProbeEnabled, data\n"
|
---|
| 790 | );
|
---|
| 791 | uint32_t cProbes = 0;
|
---|
| 792 | RTListForEach(&g_ProviderHead, pProvider, VTGPROVIDER, ListEntry)
|
---|
| 793 | {
|
---|
| 794 | RTListForEach(&pProvider->ProbeHead, pProbe, VTGPROBE, ListEntry)
|
---|
| 795 | {
|
---|
| 796 | ScmStreamPrintf(pStrm,
|
---|
| 797 | "VTG_GLOBAL g_cVTGProbeEnabled_%s_%s, data\n"
|
---|
| 798 | " dd 0\n",
|
---|
| 799 | pProvider->pszName, pProbe->pszMangledName);
|
---|
| 800 | cProbes++;
|
---|
| 801 | }
|
---|
| 802 | }
|
---|
| 803 | ScmStreamPrintf(pStrm, "VTG_GLOBAL g_acVTGProbeEnabled_End, data\n");
|
---|
| 804 | if (cProbes >= _32K)
|
---|
| 805 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "Too many probes: %u (max %u)", cProbes, _32K - 1);
|
---|
| 806 |
|
---|
| 807 |
|
---|
| 808 | /*
|
---|
[40570] | 809 | * Emit code for the stub functions.
|
---|
| 810 | */
|
---|
[40860] | 811 | bool const fWin64 = g_cBits == 64 && (!strcmp(g_pszAssemblerFmtVal, "win64") || !strcmp(g_pszAssemblerFmtVal, "pe64"));
|
---|
[46862] | 812 | bool const fElf = !strcmp(g_pszAssemblerFmtVal, "elf32") || !strcmp(g_pszAssemblerFmtVal, "elf64");
|
---|
[40572] | 813 | ScmStreamPrintf(pStrm,
|
---|
| 814 | "\n"
|
---|
| 815 | ";\n"
|
---|
| 816 | "; Prob stubs.\n"
|
---|
| 817 | ";\n"
|
---|
| 818 | "BEGINCODE\n"
|
---|
[46862] | 819 | );
|
---|
| 820 | if (g_fProbeFnImported)
|
---|
[40860] | 821 | ScmStreamPrintf(pStrm,
|
---|
[46862] | 822 | "EXTERN_IMP2 %s\n"
|
---|
| 823 | "BEGINCODE ; EXTERN_IMP2 changes section\n",
|
---|
[40860] | 824 | g_pszProbeFnName);
|
---|
[46862] | 825 | else
|
---|
| 826 | ScmStreamPrintf(pStrm, "extern NAME(%s)\n", g_pszProbeFnName);
|
---|
[40860] | 827 |
|
---|
[40572] | 828 | RTListForEach(&g_ProviderHead, pProvider, VTGPROVIDER, ListEntry)
|
---|
| 829 | {
|
---|
| 830 | RTListForEach(&pProvider->ProbeHead, pProbe, VTGPROBE, ListEntry)
|
---|
| 831 | {
|
---|
| 832 | ScmStreamPrintf(pStrm,
|
---|
| 833 | "\n"
|
---|
[40594] | 834 | "VTG_GLOBAL VTGProbeStub_%s_%s, function; (VBOXTPGPROBELOC pVTGProbeLoc",
|
---|
[40619] | 835 | pProvider->pszName, pProbe->pszMangledName);
|
---|
[40572] | 836 | RTListForEach(&pProbe->ArgHead, pArg, VTGARG, ListEntry)
|
---|
| 837 | {
|
---|
[41338] | 838 | ScmStreamPrintf(pStrm, ", %s %s", pArg->pszTracerType, pArg->pszName);
|
---|
[40572] | 839 | }
|
---|
| 840 | ScmStreamPrintf(pStrm,
|
---|
| 841 | ");\n");
|
---|
[40570] | 842 |
|
---|
[40572] | 843 | /*
|
---|
| 844 | * Check if the probe in question is enabled.
|
---|
| 845 | */
|
---|
| 846 | if (g_cBits == 32)
|
---|
| 847 | ScmStreamPrintf(pStrm,
|
---|
| 848 | " mov eax, [esp + 4]\n"
|
---|
| 849 | " test byte [eax+3], 0x80 ; fEnabled == true?\n"
|
---|
| 850 | " jz .return ; jump on false\n");
|
---|
| 851 | else if (fWin64)
|
---|
| 852 | ScmStreamPrintf(pStrm,
|
---|
| 853 | " test byte [rcx+3], 0x80 ; fEnabled == true?\n"
|
---|
| 854 | " jz .return ; jump on false\n");
|
---|
| 855 | else
|
---|
| 856 | ScmStreamPrintf(pStrm,
|
---|
| 857 | " test byte [rdi+3], 0x80 ; fEnabled == true?\n"
|
---|
| 858 | " jz .return ; jump on false\n");
|
---|
| 859 |
|
---|
| 860 | /*
|
---|
[40830] | 861 | * Jump to the fire-probe function.
|
---|
| 862 | */
|
---|
| 863 | if (g_cBits == 32)
|
---|
[46862] | 864 | ScmStreamPrintf(pStrm, g_fPic && fElf ?
|
---|
[41362] | 865 | " jmp %s wrt ..plt\n"
|
---|
[40975] | 866 | : g_fProbeFnImported ?
|
---|
[40830] | 867 | " mov ecx, IMP2(%s)\n"
|
---|
| 868 | " jmp ecx\n"
|
---|
| 869 | :
|
---|
| 870 | " jmp NAME(%s)\n"
|
---|
| 871 | , g_pszProbeFnName);
|
---|
| 872 | else
|
---|
[46862] | 873 | ScmStreamPrintf(pStrm, g_fPic && fElf ?
|
---|
[40975] | 874 | " jmp [rel %s wrt ..got]\n"
|
---|
| 875 | : g_fProbeFnImported ?
|
---|
[46558] | 876 | " jmp IMP2(%s)\n"
|
---|
[40830] | 877 | :
|
---|
| 878 | " jmp NAME(%s)\n"
|
---|
| 879 | , g_pszProbeFnName);
|
---|
[40572] | 880 |
|
---|
| 881 | ScmStreamPrintf(pStrm,
|
---|
| 882 | ".return:\n"
|
---|
| 883 | " ret ; The probe was disabled, return\n"
|
---|
| 884 | "\n");
|
---|
| 885 | }
|
---|
| 886 | }
|
---|
| 887 |
|
---|
[40554] | 888 | return RTEXITCODE_SUCCESS;
|
---|
| 889 | }
|
---|
| 890 |
|
---|
| 891 |
|
---|
| 892 | static RTEXITCODE generateObject(const char *pszOutput, const char *pszTempAsm)
|
---|
| 893 | {
|
---|
| 894 | if (!pszTempAsm)
|
---|
| 895 | {
|
---|
[40558] | 896 | size_t cch = strlen(pszOutput);
|
---|
[40554] | 897 | char *psz = (char *)alloca(cch + sizeof(".asm"));
|
---|
| 898 | memcpy(psz, pszOutput, cch);
|
---|
| 899 | memcpy(psz + cch, ".asm", sizeof(".asm"));
|
---|
| 900 | pszTempAsm = psz;
|
---|
| 901 | }
|
---|
| 902 |
|
---|
| 903 | RTEXITCODE rcExit = generateFile(pszTempAsm, "assembly", generateAssembly);
|
---|
| 904 | if (rcExit == RTEXITCODE_SUCCESS)
|
---|
| 905 | rcExit = generateInvokeAssembler(pszOutput, pszTempAsm);
|
---|
| 906 | RTFileDelete(pszTempAsm);
|
---|
| 907 | return rcExit;
|
---|
| 908 | }
|
---|
| 909 |
|
---|
| 910 |
|
---|
[40558] | 911 | static RTEXITCODE generateProbeDefineName(char *pszBuf, size_t cbBuf, const char *pszProvider, const char *pszProbe)
|
---|
| 912 | {
|
---|
| 913 | size_t cbMax = strlen(pszProvider) + 1 + strlen(pszProbe) + 1;
|
---|
| 914 | if (cbMax > cbBuf || cbMax > 80)
|
---|
| 915 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "Probe '%s' in provider '%s' ends up with a too long defined\n", pszProbe, pszProvider);
|
---|
| 916 |
|
---|
| 917 | while (*pszProvider)
|
---|
| 918 | *pszBuf++ = RT_C_TO_UPPER(*pszProvider++);
|
---|
| 919 |
|
---|
| 920 | *pszBuf++ = '_';
|
---|
| 921 |
|
---|
| 922 | while (*pszProbe)
|
---|
| 923 | {
|
---|
| 924 | if (pszProbe[0] == '_' && pszProbe[1] == '_')
|
---|
| 925 | pszProbe++;
|
---|
| 926 | *pszBuf++ = RT_C_TO_UPPER(*pszProbe++);
|
---|
| 927 | }
|
---|
| 928 |
|
---|
| 929 | *pszBuf = '\0';
|
---|
| 930 | return RTEXITCODE_SUCCESS;
|
---|
| 931 | }
|
---|
| 932 |
|
---|
[41342] | 933 |
|
---|
[58920] | 934 | static RTEXITCODE generateProviderDefineName(char *pszBuf, size_t cbBuf, const char *pszProvider)
|
---|
| 935 | {
|
---|
| 936 | size_t cbMax = strlen(pszProvider) + 1;
|
---|
| 937 | if (cbMax > cbBuf || cbMax > 80)
|
---|
| 938 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "Provider '%s' ends up with a too long defined\n", pszProvider);
|
---|
| 939 |
|
---|
| 940 | while (*pszProvider)
|
---|
| 941 | *pszBuf++ = RT_C_TO_UPPER(*pszProvider++);
|
---|
| 942 |
|
---|
| 943 | *pszBuf = '\0';
|
---|
| 944 | return RTEXITCODE_SUCCESS;
|
---|
| 945 | }
|
---|
| 946 |
|
---|
| 947 |
|
---|
[41338] | 948 | /**
|
---|
| 949 | * Called via generateFile to generate the header file.
|
---|
| 950 | *
|
---|
| 951 | * @returns Exit code status.
|
---|
| 952 | * @param pStrm The output stream.
|
---|
| 953 | */
|
---|
[41342] | 954 | static RTEXITCODE generateHeader(PSCMSTREAM pStrm)
|
---|
[40554] | 955 | {
|
---|
[40558] | 956 | /*
|
---|
| 957 | * Calc the double inclusion blocker define and then write the file header.
|
---|
| 958 | */
|
---|
| 959 | char szTmp[4096];
|
---|
| 960 | const char *pszName = RTPathFilename(g_pszScript);
|
---|
| 961 | size_t cchName = strlen(pszName);
|
---|
| 962 | if (cchName >= sizeof(szTmp) - 64)
|
---|
| 963 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "File name is too long '%s'", pszName);
|
---|
| 964 | szTmp[0] = '_';
|
---|
| 965 | szTmp[1] = '_';
|
---|
| 966 | szTmp[2] = '_';
|
---|
| 967 | memcpy(&szTmp[3], pszName, cchName);
|
---|
| 968 | szTmp[3 + cchName + 0] = '_';
|
---|
| 969 | szTmp[3 + cchName + 1] = '_';
|
---|
| 970 | szTmp[3 + cchName + 2] = '_';
|
---|
| 971 | szTmp[3 + cchName + 3] = '\0';
|
---|
| 972 | char *psz = &szTmp[3];
|
---|
| 973 | while (*psz)
|
---|
| 974 | {
|
---|
| 975 | if (!RT_C_IS_ALNUM(*psz) && *psz != '_')
|
---|
| 976 | *psz = '_';
|
---|
| 977 | psz++;
|
---|
| 978 | }
|
---|
| 979 |
|
---|
| 980 | ScmStreamPrintf(pStrm,
|
---|
| 981 | "/* $Id: VBoxTpG.cpp 104620 2024-05-14 06:56:35Z vboxsync $ */\n"
|
---|
| 982 | "/** @file\n"
|
---|
[41338] | 983 | " * Automatically generated from %s. Do NOT edit!\n"
|
---|
[40558] | 984 | " */\n"
|
---|
| 985 | "\n"
|
---|
| 986 | "#ifndef %s\n"
|
---|
| 987 | "#define %s\n"
|
---|
[76506] | 988 | "#ifndef RT_WITHOUT_PRAGMA_ONCE\n"
|
---|
| 989 | "# pragma once\n"
|
---|
| 990 | "#endif\n"
|
---|
[40558] | 991 | "\n"
|
---|
[40594] | 992 | "#include <VBox/VBoxTpG.h>\n"
|
---|
[40558] | 993 | "\n"
|
---|
[41338] | 994 | "#ifndef %s\n"
|
---|
| 995 | "# error \"Expected '%s' to be defined\"\n"
|
---|
| 996 | "#endif\n"
|
---|
| 997 | "\n"
|
---|
[40594] | 998 | "RT_C_DECLS_BEGIN\n"
|
---|
[40558] | 999 | "\n"
|
---|
[40594] | 1000 | "#ifdef VBOX_WITH_DTRACE\n"
|
---|
[40558] | 1001 | "\n"
|
---|
[40826] | 1002 | "# ifdef _MSC_VER\n"
|
---|
| 1003 | "# pragma data_seg(VTG_LOC_SECT)\n"
|
---|
| 1004 | "# pragma data_seg()\n"
|
---|
| 1005 | "# endif\n"
|
---|
| 1006 | "\n"
|
---|
[40558] | 1007 | ,
|
---|
| 1008 | g_pszScript,
|
---|
| 1009 | szTmp,
|
---|
[41338] | 1010 | szTmp,
|
---|
[41342] | 1011 | g_pszContextDefine,
|
---|
| 1012 | g_pszContextDefine);
|
---|
[40558] | 1013 |
|
---|
| 1014 | /*
|
---|
| 1015 | * Declare data, code and macros for each probe.
|
---|
| 1016 | */
|
---|
| 1017 | PVTGPROVIDER pProv;
|
---|
[40594] | 1018 | PVTGPROBE pProbe;
|
---|
| 1019 | PVTGARG pArg;
|
---|
[40558] | 1020 | RTListForEach(&g_ProviderHead, pProv, VTGPROVIDER, ListEntry)
|
---|
| 1021 | {
|
---|
[58920] | 1022 | /* This macro is not available in ring-3 because we don't have
|
---|
| 1023 | anything similar available for native dtrace. */
|
---|
| 1024 | ScmStreamPrintf(pStrm, "\n\n");
|
---|
| 1025 | if (g_fTypeContext != VTG_TYPE_CTX_R3)
|
---|
| 1026 | {
|
---|
| 1027 | generateProviderDefineName(szTmp, sizeof(szTmp), pProv->pszName);
|
---|
| 1028 | ScmStreamPrintf(pStrm,
|
---|
[58976] | 1029 | "extern uint32_t const volatile g_cVTGProviderProbesEnabled_%s;\n"
|
---|
[58920] | 1030 | "# define %s_ANY_PROBES_ENABLED() \\\n"
|
---|
[58964] | 1031 | " (RT_UNLIKELY(g_cVTGProviderProbesEnabled_%s != 0))\n"
|
---|
[58976] | 1032 | "extern uint32_t const volatile g_cVTGProviderSettingsSeqNo_%s;\n"
|
---|
| 1033 | "# define %s_GET_SETTINGS_SEQ_NO() (g_cVTGProviderSettingsSeqNo_%s)\n"
|
---|
[58920] | 1034 | "\n",
|
---|
| 1035 | pProv->pszName,
|
---|
[58976] | 1036 | szTmp, pProv->pszName,
|
---|
| 1037 | pProv->pszName,
|
---|
[58920] | 1038 | szTmp, pProv->pszName);
|
---|
| 1039 | }
|
---|
| 1040 |
|
---|
[40558] | 1041 | RTListForEach(&pProv->ProbeHead, pProbe, VTGPROBE, ListEntry)
|
---|
| 1042 | {
|
---|
| 1043 | ScmStreamPrintf(pStrm,
|
---|
[58997] | 1044 | "extern uint32_t const volatile g_cVTGProbeEnabled_%s_%s;\n"
|
---|
| 1045 | "extern VTGDESCPROBE g_VTGProbeData_%s_%s;\n"
|
---|
| 1046 | "DECLASM(void) VTGProbeStub_%s_%s(PVTGPROBELOC",
|
---|
[40619] | 1047 | pProv->pszName, pProbe->pszMangledName,
|
---|
| 1048 | pProv->pszName, pProbe->pszMangledName,
|
---|
| 1049 | pProv->pszName, pProbe->pszMangledName);
|
---|
[40558] | 1050 | RTListForEach(&pProbe->ArgHead, pArg, VTGARG, ListEntry)
|
---|
| 1051 | {
|
---|
[41338] | 1052 | ScmStreamPrintf(pStrm, ", %s", pArg->pszCtxType);
|
---|
[40558] | 1053 | }
|
---|
[40619] | 1054 | generateProbeDefineName(szTmp, sizeof(szTmp), pProv->pszName, pProbe->pszMangledName);
|
---|
[40558] | 1055 | ScmStreamPrintf(pStrm,
|
---|
| 1056 | ");\n"
|
---|
[58964] | 1057 | "# define %s_ENABLED() (RT_UNLIKELY(g_cVTGProbeEnabled_%s_%s != 0))\n"
|
---|
[58936] | 1058 | "# define %s_ENABLED_RAW() (g_cVTGProbeEnabled_%s_%s)\n"
|
---|
[40594] | 1059 | "# define %s("
|
---|
[58936] | 1060 | ,
|
---|
| 1061 | szTmp, pProv->pszName, pProbe->pszMangledName,
|
---|
| 1062 | szTmp, pProv->pszName, pProbe->pszMangledName,
|
---|
[40558] | 1063 | szTmp);
|
---|
| 1064 | RTListForEach(&pProbe->ArgHead, pArg, VTGARG, ListEntry)
|
---|
| 1065 | {
|
---|
| 1066 | if (RTListNodeIsFirst(&pProbe->ArgHead, &pArg->ListEntry))
|
---|
| 1067 | ScmStreamPrintf(pStrm, "%s", pArg->pszName);
|
---|
| 1068 | else
|
---|
| 1069 | ScmStreamPrintf(pStrm, ", %s", pArg->pszName);
|
---|
| 1070 | }
|
---|
| 1071 | ScmStreamPrintf(pStrm,
|
---|
| 1072 | ") \\\n"
|
---|
| 1073 | " do { \\\n"
|
---|
[41117] | 1074 | " if (RT_UNLIKELY(g_cVTGProbeEnabled_%s_%s)) \\\n"
|
---|
[40558] | 1075 | " { \\\n"
|
---|
[40594] | 1076 | " VTG_DECL_VTGPROBELOC(s_VTGProbeLoc) = \\\n"
|
---|
[41117] | 1077 | " { __LINE__, 0, 0, __FUNCTION__, &g_VTGProbeData_%s_%s }; \\\n"
|
---|
[40572] | 1078 | " VTGProbeStub_%s_%s(&s_VTGProbeLoc",
|
---|
[40619] | 1079 | pProv->pszName, pProbe->pszMangledName,
|
---|
| 1080 | pProv->pszName, pProbe->pszMangledName,
|
---|
| 1081 | pProv->pszName, pProbe->pszMangledName);
|
---|
[40558] | 1082 | RTListForEach(&pProbe->ArgHead, pArg, VTGARG, ListEntry)
|
---|
| 1083 | {
|
---|
[41338] | 1084 | ScmStreamPrintf(pStrm, pArg->pszArgPassingFmt, pArg->pszName);
|
---|
[40558] | 1085 | }
|
---|
| 1086 | ScmStreamPrintf(pStrm,
|
---|
[40572] | 1087 | "); \\\n"
|
---|
[40636] | 1088 | " } \\\n"
|
---|
| 1089 | " { \\\n" );
|
---|
[40572] | 1090 | RTListForEach(&pProbe->ArgHead, pArg, VTGARG, ListEntry)
|
---|
| 1091 | {
|
---|
[41338] | 1092 | if ((pArg->fType & (VTG_TYPE_FIXED_SIZED | VTG_TYPE_AUTO_CONV_PTR)) == VTG_TYPE_FIXED_SIZED)
|
---|
[40892] | 1093 | ScmStreamPrintf(pStrm,
|
---|
| 1094 | " AssertCompile(sizeof(%s) == %u); \\\n"
|
---|
| 1095 | " AssertCompile(sizeof(%s) <= %u); \\\n",
|
---|
[41338] | 1096 | pArg->pszTracerType, pArg->fType & VTG_TYPE_SIZE_MASK,
|
---|
[40892] | 1097 | pArg->pszName, pArg->fType & VTG_TYPE_SIZE_MASK);
|
---|
| 1098 | else if (pArg->fType & (VTG_TYPE_POINTER | VTG_TYPE_HC_ARCH_SIZED))
|
---|
| 1099 | ScmStreamPrintf(pStrm,
|
---|
| 1100 | " AssertCompile(sizeof(%s) <= sizeof(uintptr_t)); \\\n"
|
---|
| 1101 | " AssertCompile(sizeof(%s) <= sizeof(uintptr_t)); \\\n",
|
---|
| 1102 | pArg->pszName,
|
---|
[41338] | 1103 | pArg->pszTracerType);
|
---|
[40572] | 1104 | }
|
---|
| 1105 | ScmStreamPrintf(pStrm,
|
---|
[40636] | 1106 | " } \\\n"
|
---|
[40558] | 1107 | " } while (0)\n"
|
---|
| 1108 | "\n");
|
---|
| 1109 | }
|
---|
| 1110 | }
|
---|
| 1111 |
|
---|
[40594] | 1112 | ScmStreamPrintf(pStrm,
|
---|
| 1113 | "\n"
|
---|
| 1114 | "#else\n"
|
---|
| 1115 | "\n");
|
---|
| 1116 | RTListForEach(&g_ProviderHead, pProv, VTGPROVIDER, ListEntry)
|
---|
| 1117 | {
|
---|
[58997] | 1118 | if (g_fTypeContext != VTG_TYPE_CTX_R3)
|
---|
| 1119 | {
|
---|
| 1120 | generateProviderDefineName(szTmp, sizeof(szTmp), pProv->pszName);
|
---|
| 1121 | ScmStreamPrintf(pStrm,
|
---|
| 1122 | "# define %s_ANY_PROBES_ENABLED() (false)\n"
|
---|
| 1123 | "# define %s_GET_SETTINGS_SEQ_NO() UINT32_C(0)\n"
|
---|
| 1124 | "\n",
|
---|
| 1125 | szTmp, szTmp);
|
---|
| 1126 | }
|
---|
| 1127 |
|
---|
[40594] | 1128 | RTListForEach(&pProv->ProbeHead, pProbe, VTGPROBE, ListEntry)
|
---|
| 1129 | {
|
---|
[40619] | 1130 | generateProbeDefineName(szTmp, sizeof(szTmp), pProv->pszName, pProbe->pszMangledName);
|
---|
[40594] | 1131 | ScmStreamPrintf(pStrm,
|
---|
| 1132 | "# define %s_ENABLED() (false)\n"
|
---|
[58997] | 1133 | "# define %s_ENABLED_RAW() UINT32_C(0)\n"
|
---|
[40594] | 1134 | "# define %s("
|
---|
[58997] | 1135 | , szTmp, szTmp, szTmp);
|
---|
[40594] | 1136 | RTListForEach(&pProbe->ArgHead, pArg, VTGARG, ListEntry)
|
---|
| 1137 | {
|
---|
| 1138 | if (RTListNodeIsFirst(&pProbe->ArgHead, &pArg->ListEntry))
|
---|
| 1139 | ScmStreamPrintf(pStrm, "%s", pArg->pszName);
|
---|
| 1140 | else
|
---|
| 1141 | ScmStreamPrintf(pStrm, ", %s", pArg->pszName);
|
---|
| 1142 | }
|
---|
| 1143 | ScmStreamPrintf(pStrm,
|
---|
| 1144 | ") do { } while (0)\n");
|
---|
| 1145 | }
|
---|
| 1146 | }
|
---|
| 1147 |
|
---|
[40558] | 1148 | ScmStreamWrite(pStrm, RT_STR_TUPLE("\n"
|
---|
[40594] | 1149 | "#endif\n"
|
---|
| 1150 | "\n"
|
---|
[40558] | 1151 | "RT_C_DECLS_END\n"
|
---|
| 1152 | "#endif\n"));
|
---|
[40554] | 1153 | return RTEXITCODE_SUCCESS;
|
---|
| 1154 | }
|
---|
| 1155 |
|
---|
| 1156 |
|
---|
[41342] | 1157 | /**
|
---|
| 1158 | * Called via generateFile to generate the wrapper header file.
|
---|
| 1159 | *
|
---|
| 1160 | * @returns Exit code status.
|
---|
| 1161 | * @param pStrm The output stream.
|
---|
| 1162 | */
|
---|
| 1163 | static RTEXITCODE generateWrapperHeader(PSCMSTREAM pStrm)
|
---|
[40554] | 1164 | {
|
---|
[41342] | 1165 | /*
|
---|
| 1166 | * Calc the double inclusion blocker define and then write the file header.
|
---|
| 1167 | */
|
---|
| 1168 | char szTmp[4096];
|
---|
| 1169 | const char *pszName = RTPathFilename(g_pszScript);
|
---|
| 1170 | size_t cchName = strlen(pszName);
|
---|
| 1171 | if (cchName >= sizeof(szTmp) - 64)
|
---|
| 1172 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "File name is too long '%s'", pszName);
|
---|
| 1173 | szTmp[0] = '_';
|
---|
| 1174 | szTmp[1] = '_';
|
---|
| 1175 | szTmp[2] = '_';
|
---|
| 1176 | memcpy(&szTmp[3], pszName, cchName);
|
---|
| 1177 | strcpy(&szTmp[3 + cchName ], "___WRAPPER___");
|
---|
| 1178 | char *psz = &szTmp[3];
|
---|
| 1179 | while (*psz)
|
---|
| 1180 | {
|
---|
| 1181 | if (!RT_C_IS_ALNUM(*psz) && *psz != '_')
|
---|
| 1182 | *psz = '_';
|
---|
| 1183 | psz++;
|
---|
| 1184 | }
|
---|
| 1185 |
|
---|
| 1186 | ScmStreamPrintf(pStrm,
|
---|
| 1187 | "/* $Id: VBoxTpG.cpp 104620 2024-05-14 06:56:35Z vboxsync $ */\n"
|
---|
| 1188 | "/** @file\n"
|
---|
| 1189 | " * Automatically generated from %s. Do NOT edit!\n"
|
---|
| 1190 | " */\n"
|
---|
| 1191 | "\n"
|
---|
| 1192 | "#ifndef %s\n"
|
---|
| 1193 | "#define %s\n"
|
---|
| 1194 | "\n"
|
---|
| 1195 | "#include <VBox/VBoxTpG.h>\n"
|
---|
| 1196 | "\n"
|
---|
| 1197 | "#ifndef %s\n"
|
---|
| 1198 | "# error \"Expected '%s' to be defined\"\n"
|
---|
| 1199 | "#endif\n"
|
---|
| 1200 | "\n"
|
---|
| 1201 | "#ifdef VBOX_WITH_DTRACE\n"
|
---|
| 1202 | "\n"
|
---|
| 1203 | ,
|
---|
| 1204 | g_pszScript,
|
---|
| 1205 | szTmp,
|
---|
| 1206 | szTmp,
|
---|
| 1207 | g_pszContextDefine,
|
---|
| 1208 | g_pszContextDefine);
|
---|
| 1209 |
|
---|
| 1210 | /*
|
---|
| 1211 | * Declare macros for each probe.
|
---|
| 1212 | */
|
---|
| 1213 | PVTGPROVIDER pProv;
|
---|
| 1214 | PVTGPROBE pProbe;
|
---|
| 1215 | PVTGARG pArg;
|
---|
| 1216 | RTListForEach(&g_ProviderHead, pProv, VTGPROVIDER, ListEntry)
|
---|
| 1217 | {
|
---|
| 1218 | RTListForEach(&pProv->ProbeHead, pProbe, VTGPROBE, ListEntry)
|
---|
| 1219 | {
|
---|
| 1220 | generateProbeDefineName(szTmp, sizeof(szTmp), pProv->pszName, pProbe->pszMangledName);
|
---|
| 1221 | ScmStreamPrintf(pStrm,
|
---|
| 1222 | "# define %s("
|
---|
| 1223 | , szTmp);
|
---|
| 1224 | RTListForEach(&pProbe->ArgHead, pArg, VTGARG, ListEntry)
|
---|
| 1225 | {
|
---|
| 1226 | if (RTListNodeIsFirst(&pProbe->ArgHead, &pArg->ListEntry))
|
---|
| 1227 | ScmStreamPrintf(pStrm, "%s", pArg->pszName);
|
---|
| 1228 | else
|
---|
| 1229 | ScmStreamPrintf(pStrm, ", %s", pArg->pszName);
|
---|
| 1230 | }
|
---|
| 1231 | ScmStreamPrintf(pStrm,
|
---|
| 1232 | ") \\\n"
|
---|
| 1233 | " do { \\\n"
|
---|
| 1234 | " if (RT_UNLIKELY(%s_ENABLED())) \\\n"
|
---|
| 1235 | " { \\\n"
|
---|
| 1236 | " %s_ORIGINAL("
|
---|
| 1237 | , szTmp, szTmp);
|
---|
| 1238 | RTListForEach(&pProbe->ArgHead, pArg, VTGARG, ListEntry)
|
---|
| 1239 | {
|
---|
| 1240 | const char *pszFmt = pArg->pszArgPassingFmt;
|
---|
| 1241 | if (pArg->fType & VTG_TYPE_AUTO_CONV_PTR)
|
---|
| 1242 | {
|
---|
| 1243 | /* Casting is required. ASSUMES sizeof(RTR0PTR) == sizeof(RTR3PTR) - safe! */
|
---|
| 1244 | pszFmt += sizeof(", ") - 1;
|
---|
| 1245 | if (RTListNodeIsFirst(&pProbe->ArgHead, &pArg->ListEntry))
|
---|
| 1246 | ScmStreamPrintf(pStrm, "(%s)%M", pArg->pszTracerType, pszFmt, pArg->pszName);
|
---|
| 1247 | else
|
---|
| 1248 | ScmStreamPrintf(pStrm, ", (%s)%M", pArg->pszTracerType, pszFmt, pArg->pszName);
|
---|
| 1249 | }
|
---|
[54067] | 1250 | else if (pArg->fType & VTG_TYPE_CONST_CHAR_PTR)
|
---|
| 1251 | {
|
---|
| 1252 | /* Casting from 'const char *' (probe) to 'char *' (dtrace) is required to shut up warnings. */
|
---|
| 1253 | pszFmt += sizeof(", ") - 1;
|
---|
| 1254 | if (RTListNodeIsFirst(&pProbe->ArgHead, &pArg->ListEntry))
|
---|
| 1255 | ScmStreamPrintf(pStrm, "(char *)%M", pszFmt, pArg->pszName);
|
---|
| 1256 | else
|
---|
| 1257 | ScmStreamPrintf(pStrm, ", (char *)%M", pszFmt, pArg->pszName);
|
---|
| 1258 | }
|
---|
[41342] | 1259 | else
|
---|
| 1260 | {
|
---|
| 1261 | if (RTListNodeIsFirst(&pProbe->ArgHead, &pArg->ListEntry))
|
---|
| 1262 | ScmStreamPrintf(pStrm, pArg->pszArgPassingFmt + sizeof(", ") - 1, pArg->pszName);
|
---|
| 1263 | else
|
---|
| 1264 | ScmStreamPrintf(pStrm, pArg->pszArgPassingFmt, pArg->pszName);
|
---|
| 1265 | }
|
---|
| 1266 | }
|
---|
| 1267 | ScmStreamPrintf(pStrm,
|
---|
| 1268 | "); \\\n"
|
---|
| 1269 | " } \\\n"
|
---|
| 1270 | " } while (0)\n"
|
---|
| 1271 | "\n");
|
---|
| 1272 | }
|
---|
| 1273 | }
|
---|
| 1274 |
|
---|
| 1275 | ScmStreamPrintf(pStrm,
|
---|
| 1276 | "\n"
|
---|
| 1277 | "#else\n"
|
---|
| 1278 | "\n");
|
---|
| 1279 | RTListForEach(&g_ProviderHead, pProv, VTGPROVIDER, ListEntry)
|
---|
| 1280 | {
|
---|
| 1281 | RTListForEach(&pProv->ProbeHead, pProbe, VTGPROBE, ListEntry)
|
---|
| 1282 | {
|
---|
| 1283 | generateProbeDefineName(szTmp, sizeof(szTmp), pProv->pszName, pProbe->pszMangledName);
|
---|
| 1284 | ScmStreamPrintf(pStrm,
|
---|
| 1285 | "# define %s("
|
---|
| 1286 | , szTmp);
|
---|
| 1287 | RTListForEach(&pProbe->ArgHead, pArg, VTGARG, ListEntry)
|
---|
| 1288 | {
|
---|
| 1289 | if (RTListNodeIsFirst(&pProbe->ArgHead, &pArg->ListEntry))
|
---|
| 1290 | ScmStreamPrintf(pStrm, "%s", pArg->pszName);
|
---|
| 1291 | else
|
---|
| 1292 | ScmStreamPrintf(pStrm, ", %s", pArg->pszName);
|
---|
| 1293 | }
|
---|
| 1294 | ScmStreamPrintf(pStrm,
|
---|
| 1295 | ") do { } while (0)\n");
|
---|
| 1296 | }
|
---|
| 1297 | }
|
---|
| 1298 |
|
---|
| 1299 | ScmStreamWrite(pStrm, RT_STR_TUPLE("\n"
|
---|
| 1300 | "#endif\n"
|
---|
| 1301 | "\n"
|
---|
| 1302 | "#endif\n"));
|
---|
| 1303 | return RTEXITCODE_SUCCESS;
|
---|
[40554] | 1304 | }
|
---|
| 1305 |
|
---|
| 1306 |
|
---|
| 1307 | /**
|
---|
| 1308 | * Parser error with line and position.
|
---|
| 1309 | *
|
---|
| 1310 | * @returns RTEXITCODE_FAILURE.
|
---|
[88956] | 1311 | * @param pStrm The stream.
|
---|
| 1312 | * @param fAbs Absolute or relative offset.
|
---|
| 1313 | * @param offSeek When @a fAbs is @c false, the offset from the current
|
---|
| 1314 | * position to the point of failure. When @a fAbs is @c
|
---|
| 1315 | * true, it's the absolute position.
|
---|
| 1316 | * @param pszFormat The message format string.
|
---|
| 1317 | * @param va Format arguments.
|
---|
[40554] | 1318 | */
|
---|
[88956] | 1319 | static RTEXITCODE parseErrorExV(PSCMSTREAM pStrm, bool fAbs, size_t offSeek, const char *pszFormat, va_list va)
|
---|
[40554] | 1320 | {
|
---|
[88956] | 1321 | if (fAbs)
|
---|
| 1322 | ScmStreamSeekAbsolute(pStrm, offSeek);
|
---|
| 1323 | else if (offSeek != 0)
|
---|
| 1324 | ScmStreamSeekRelative(pStrm, -(ssize_t)offSeek);
|
---|
[40554] | 1325 | size_t const off = ScmStreamTell(pStrm);
|
---|
| 1326 | size_t const iLine = ScmStreamTellLine(pStrm);
|
---|
| 1327 | ScmStreamSeekByLine(pStrm, iLine);
|
---|
| 1328 | size_t const offLine = ScmStreamTell(pStrm);
|
---|
| 1329 |
|
---|
[88956] | 1330 | va_list va2;
|
---|
| 1331 | va_copy(va2, va);
|
---|
| 1332 | RTPrintf("%s:%d:%zd: error: %N.\n", g_pszScript, iLine + 1, off - offLine + 1, pszFormat, &va2);
|
---|
| 1333 | va_end(va2);
|
---|
[40554] | 1334 |
|
---|
| 1335 | size_t cchLine;
|
---|
| 1336 | SCMEOL enmEof;
|
---|
| 1337 | const char *pszLine = ScmStreamGetLineByNo(pStrm, iLine, &cchLine, &enmEof);
|
---|
| 1338 | if (pszLine)
|
---|
| 1339 | RTPrintf(" %.*s\n"
|
---|
| 1340 | " %*s^\n",
|
---|
| 1341 | cchLine, pszLine, off - offLine, "");
|
---|
| 1342 | return RTEXITCODE_FAILURE;
|
---|
| 1343 | }
|
---|
| 1344 |
|
---|
[40555] | 1345 |
|
---|
[40554] | 1346 | /**
|
---|
[40555] | 1347 | * Parser error with line and position.
|
---|
| 1348 | *
|
---|
| 1349 | * @returns RTEXITCODE_FAILURE.
|
---|
[88956] | 1350 | * @param pStrm The stream.
|
---|
| 1351 | * @param off The offset from the current position to the point of
|
---|
| 1352 | * failure.
|
---|
| 1353 | * @param pszFormat The message format string.
|
---|
| 1354 | * @param ... Format arguments.
|
---|
[40555] | 1355 | */
|
---|
[88956] | 1356 | static RTEXITCODE parseError(PSCMSTREAM pStrm, size_t off, const char *pszFormat, ...)
|
---|
[40555] | 1357 | {
|
---|
[88956] | 1358 | va_list va;
|
---|
| 1359 | va_start(va, pszFormat);
|
---|
| 1360 | RTEXITCODE rcExit = parseErrorExV(pStrm, false, off, pszFormat, va);
|
---|
| 1361 | va_end(va);
|
---|
| 1362 | return rcExit;
|
---|
[40555] | 1363 | }
|
---|
| 1364 |
|
---|
[58920] | 1365 |
|
---|
[40555] | 1366 | /**
|
---|
[88956] | 1367 | * Parser error with line and position, absolute version.
|
---|
| 1368 | *
|
---|
| 1369 | * @returns RTEXITCODE_FAILURE.
|
---|
| 1370 | * @param pStrm The stream.
|
---|
| 1371 | * @param off The offset from the current position to the point of
|
---|
| 1372 | * failure.
|
---|
| 1373 | * @param pszFormat The message format string.
|
---|
| 1374 | * @param ... Format arguments.
|
---|
| 1375 | */
|
---|
| 1376 | static RTEXITCODE parseErrorAbs(PSCMSTREAM pStrm, size_t off, const char *pszFormat, ...)
|
---|
| 1377 | {
|
---|
| 1378 | va_list va;
|
---|
| 1379 | va_start(va, pszFormat);
|
---|
| 1380 | RTEXITCODE rcExit = parseErrorExV(pStrm, true /*fAbs*/, off, pszFormat, va);
|
---|
| 1381 | va_end(va);
|
---|
| 1382 | return rcExit;
|
---|
| 1383 | }
|
---|
| 1384 |
|
---|
| 1385 |
|
---|
| 1386 | /**
|
---|
| 1387 | * Parser warning with line and position.
|
---|
| 1388 | *
|
---|
| 1389 | * @param pStrm The stream.
|
---|
| 1390 | * @param fAbs Absolute or relative offset.
|
---|
| 1391 | * @param offSeek When @a fAbs is @c false, the offset from the current
|
---|
| 1392 | * position to the point of failure. When @a fAbs is @c
|
---|
| 1393 | * true, it's the absolute position.
|
---|
| 1394 | * @param pszFormat The message format string.
|
---|
| 1395 | * @param va Format arguments.
|
---|
| 1396 | */
|
---|
| 1397 | static void parseWarnExV(PSCMSTREAM pStrm, bool fAbs, size_t offSeek, const char *pszFormat, va_list va)
|
---|
| 1398 | {
|
---|
| 1399 | /* Save the stream position. */
|
---|
| 1400 | size_t const offOrg = ScmStreamTell(pStrm);
|
---|
| 1401 |
|
---|
| 1402 | if (fAbs)
|
---|
| 1403 | ScmStreamSeekAbsolute(pStrm, offSeek);
|
---|
| 1404 | else if (offSeek != 0)
|
---|
| 1405 | ScmStreamSeekRelative(pStrm, -(ssize_t)offSeek);
|
---|
| 1406 | size_t const off = ScmStreamTell(pStrm);
|
---|
| 1407 | size_t const iLine = ScmStreamTellLine(pStrm);
|
---|
| 1408 | ScmStreamSeekByLine(pStrm, iLine);
|
---|
| 1409 | size_t const offLine = ScmStreamTell(pStrm);
|
---|
| 1410 |
|
---|
| 1411 | va_list va2;
|
---|
| 1412 | va_copy(va2, va);
|
---|
| 1413 | RTPrintf("%s:%d:%zd: warning: %N.\n", g_pszScript, iLine + 1, off - offLine + 1, pszFormat, &va2);
|
---|
| 1414 | va_end(va2);
|
---|
| 1415 |
|
---|
| 1416 | size_t cchLine;
|
---|
| 1417 | SCMEOL enmEof;
|
---|
| 1418 | const char *pszLine = ScmStreamGetLineByNo(pStrm, iLine, &cchLine, &enmEof);
|
---|
| 1419 | if (pszLine)
|
---|
| 1420 | RTPrintf(" %.*s\n"
|
---|
| 1421 | " %*s^\n",
|
---|
| 1422 | cchLine, pszLine, off - offLine, "");
|
---|
| 1423 |
|
---|
| 1424 | /* restore the position. */
|
---|
| 1425 | int rc = ScmStreamSeekAbsolute(pStrm, offOrg);
|
---|
| 1426 | AssertRC(rc);
|
---|
| 1427 | }
|
---|
| 1428 |
|
---|
| 1429 | #if 0 /* unused */
|
---|
| 1430 | /**
|
---|
| 1431 | * Parser warning with line and position.
|
---|
| 1432 | *
|
---|
| 1433 | * @param pStrm The stream.
|
---|
| 1434 | * @param off The offset from the current position to the point of
|
---|
| 1435 | * failure.
|
---|
| 1436 | * @param pszFormat The message format string.
|
---|
| 1437 | * @param ... Format arguments.
|
---|
| 1438 | */
|
---|
| 1439 | static void parseWarn(PSCMSTREAM pStrm, size_t off, const char *pszFormat, ...)
|
---|
| 1440 | {
|
---|
| 1441 | va_list va;
|
---|
| 1442 | va_start(va, pszFormat);
|
---|
| 1443 | parseWarnExV(pStrm, false, off, pszFormat, va);
|
---|
| 1444 | va_end(va);
|
---|
| 1445 | }
|
---|
| 1446 | #endif /* unused */
|
---|
| 1447 |
|
---|
| 1448 | /**
|
---|
| 1449 | * Parser warning with line and position, absolute version.
|
---|
| 1450 | *
|
---|
| 1451 | * @param pStrm The stream.
|
---|
| 1452 | * @param off The offset from the current position to the point of
|
---|
| 1453 | * failure.
|
---|
| 1454 | * @param pszFormat The message format string.
|
---|
| 1455 | * @param ... Format arguments.
|
---|
| 1456 | */
|
---|
| 1457 | static void parseWarnAbs(PSCMSTREAM pStrm, size_t off, const char *pszFormat, ...)
|
---|
| 1458 | {
|
---|
| 1459 | va_list va;
|
---|
| 1460 | va_start(va, pszFormat);
|
---|
| 1461 | parseWarnExV(pStrm, true /*fAbs*/, off, pszFormat, va);
|
---|
| 1462 | va_end(va);
|
---|
| 1463 | }
|
---|
| 1464 |
|
---|
| 1465 |
|
---|
| 1466 | /**
|
---|
[40554] | 1467 | * Handles a C++ one line comment.
|
---|
| 1468 | *
|
---|
| 1469 | * @returns Exit code.
|
---|
| 1470 | * @param pStrm The stream.
|
---|
| 1471 | */
|
---|
| 1472 | static RTEXITCODE parseOneLineComment(PSCMSTREAM pStrm)
|
---|
| 1473 | {
|
---|
| 1474 | ScmStreamSeekByLine(pStrm, ScmStreamTellLine(pStrm) + 1);
|
---|
| 1475 | return RTEXITCODE_SUCCESS;
|
---|
| 1476 | }
|
---|
| 1477 |
|
---|
[58920] | 1478 |
|
---|
[40554] | 1479 | /**
|
---|
| 1480 | * Handles a multi-line C/C++ comment.
|
---|
| 1481 | *
|
---|
| 1482 | * @returns Exit code.
|
---|
| 1483 | * @param pStrm The stream.
|
---|
| 1484 | */
|
---|
| 1485 | static RTEXITCODE parseMultiLineComment(PSCMSTREAM pStrm)
|
---|
| 1486 | {
|
---|
| 1487 | unsigned ch;
|
---|
| 1488 | while ((ch = ScmStreamGetCh(pStrm)) != ~(unsigned)0)
|
---|
| 1489 | {
|
---|
| 1490 | if (ch == '*')
|
---|
| 1491 | {
|
---|
| 1492 | do
|
---|
| 1493 | ch = ScmStreamGetCh(pStrm);
|
---|
| 1494 | while (ch == '*');
|
---|
| 1495 | if (ch == '/')
|
---|
| 1496 | return RTEXITCODE_SUCCESS;
|
---|
| 1497 | }
|
---|
| 1498 | }
|
---|
| 1499 |
|
---|
| 1500 | parseError(pStrm, 1, "Expected end of comment, got end of file");
|
---|
| 1501 | return RTEXITCODE_FAILURE;
|
---|
| 1502 | }
|
---|
| 1503 |
|
---|
| 1504 |
|
---|
| 1505 | /**
|
---|
| 1506 | * Skips spaces and comments.
|
---|
| 1507 | *
|
---|
| 1508 | * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE.
|
---|
| 1509 | * @param pStrm The stream..
|
---|
| 1510 | */
|
---|
| 1511 | static RTEXITCODE parseSkipSpacesAndComments(PSCMSTREAM pStrm)
|
---|
| 1512 | {
|
---|
| 1513 | unsigned ch;
|
---|
| 1514 | while ((ch = ScmStreamPeekCh(pStrm)) != ~(unsigned)0)
|
---|
| 1515 | {
|
---|
| 1516 | if (!RT_C_IS_SPACE(ch) && ch != '/')
|
---|
| 1517 | return RTEXITCODE_SUCCESS;
|
---|
[40557] | 1518 | unsigned ch2 = ScmStreamGetCh(pStrm); AssertBreak(ch == ch2); NOREF(ch2);
|
---|
[40554] | 1519 | if (ch == '/')
|
---|
| 1520 | {
|
---|
| 1521 | ch = ScmStreamGetCh(pStrm);
|
---|
| 1522 | RTEXITCODE rcExit;
|
---|
| 1523 | if (ch == '*')
|
---|
| 1524 | rcExit = parseMultiLineComment(pStrm);
|
---|
| 1525 | else if (ch == '/')
|
---|
| 1526 | rcExit = parseOneLineComment(pStrm);
|
---|
| 1527 | else
|
---|
| 1528 | rcExit = parseError(pStrm, 2, "Unexpected character");
|
---|
| 1529 | if (rcExit != RTEXITCODE_SUCCESS)
|
---|
| 1530 | return rcExit;
|
---|
| 1531 | }
|
---|
| 1532 | }
|
---|
| 1533 |
|
---|
| 1534 | return parseError(pStrm, 0, "Unexpected end of file");
|
---|
| 1535 | }
|
---|
| 1536 |
|
---|
| 1537 |
|
---|
[40555] | 1538 | /**
|
---|
| 1539 | * Skips spaces and comments, returning the next character.
|
---|
| 1540 | *
|
---|
| 1541 | * @returns Next non-space-non-comment character. ~(unsigned)0 on EOF or
|
---|
| 1542 | * failure.
|
---|
| 1543 | * @param pStrm The stream.
|
---|
| 1544 | */
|
---|
| 1545 | static unsigned parseGetNextNonSpaceNonCommentCh(PSCMSTREAM pStrm)
|
---|
| 1546 | {
|
---|
| 1547 | unsigned ch;
|
---|
| 1548 | while ((ch = ScmStreamGetCh(pStrm)) != ~(unsigned)0)
|
---|
| 1549 | {
|
---|
| 1550 | if (!RT_C_IS_SPACE(ch) && ch != '/')
|
---|
| 1551 | return ch;
|
---|
| 1552 | if (ch == '/')
|
---|
| 1553 | {
|
---|
| 1554 | ch = ScmStreamGetCh(pStrm);
|
---|
| 1555 | RTEXITCODE rcExit;
|
---|
| 1556 | if (ch == '*')
|
---|
| 1557 | rcExit = parseMultiLineComment(pStrm);
|
---|
| 1558 | else if (ch == '/')
|
---|
| 1559 | rcExit = parseOneLineComment(pStrm);
|
---|
| 1560 | else
|
---|
| 1561 | rcExit = parseError(pStrm, 2, "Unexpected character");
|
---|
| 1562 | if (rcExit != RTEXITCODE_SUCCESS)
|
---|
| 1563 | return ~(unsigned)0;
|
---|
| 1564 | }
|
---|
| 1565 | }
|
---|
[40554] | 1566 |
|
---|
[40555] | 1567 | parseError(pStrm, 0, "Unexpected end of file");
|
---|
| 1568 | return ~(unsigned)0;
|
---|
| 1569 | }
|
---|
| 1570 |
|
---|
| 1571 |
|
---|
[40556] | 1572 | /**
|
---|
[40557] | 1573 | * Get the next non-space-non-comment character on a preprocessor line.
|
---|
| 1574 | *
|
---|
| 1575 | * @returns The next character. On error message and ~(unsigned)0.
|
---|
| 1576 | * @param pStrm The stream.
|
---|
| 1577 | */
|
---|
| 1578 | static unsigned parseGetNextNonSpaceNonCommentChOnPpLine(PSCMSTREAM pStrm)
|
---|
| 1579 | {
|
---|
| 1580 | size_t off = ScmStreamTell(pStrm) - 1;
|
---|
| 1581 | unsigned ch;
|
---|
| 1582 | while ((ch = ScmStreamGetCh(pStrm)) != ~(unsigned)0)
|
---|
| 1583 | {
|
---|
| 1584 | if (RT_C_IS_SPACE(ch))
|
---|
| 1585 | {
|
---|
| 1586 | if (ch == '\n' || ch == '\r')
|
---|
| 1587 | {
|
---|
| 1588 | parseErrorAbs(pStrm, off, "Invalid preprocessor statement");
|
---|
| 1589 | break;
|
---|
| 1590 | }
|
---|
| 1591 | }
|
---|
| 1592 | else if (ch == '\\')
|
---|
| 1593 | {
|
---|
| 1594 | size_t off2 = ScmStreamTell(pStrm) - 1;
|
---|
| 1595 | ch = ScmStreamGetCh(pStrm);
|
---|
| 1596 | if (ch == '\r')
|
---|
| 1597 | ch = ScmStreamGetCh(pStrm);
|
---|
| 1598 | if (ch != '\n')
|
---|
| 1599 | {
|
---|
| 1600 | parseErrorAbs(pStrm, off2, "Expected new line");
|
---|
| 1601 | break;
|
---|
| 1602 | }
|
---|
| 1603 | }
|
---|
| 1604 | else
|
---|
| 1605 | return ch;
|
---|
| 1606 | }
|
---|
| 1607 | return ~(unsigned)0;
|
---|
| 1608 | }
|
---|
| 1609 |
|
---|
| 1610 |
|
---|
| 1611 |
|
---|
| 1612 | /**
|
---|
[40556] | 1613 | * Skips spaces and comments.
|
---|
| 1614 | *
|
---|
| 1615 | * @returns Same as ScmStreamCGetWord
|
---|
| 1616 | * @param pStrm The stream..
|
---|
| 1617 | * @param pcchWord Where to return the length.
|
---|
| 1618 | */
|
---|
| 1619 | static const char *parseGetNextCWord(PSCMSTREAM pStrm, size_t *pcchWord)
|
---|
| 1620 | {
|
---|
| 1621 | if (parseSkipSpacesAndComments(pStrm) != RTEXITCODE_SUCCESS)
|
---|
| 1622 | return NULL;
|
---|
| 1623 | return ScmStreamCGetWord(pStrm, pcchWord);
|
---|
| 1624 | }
|
---|
[40555] | 1625 |
|
---|
[40556] | 1626 |
|
---|
[40557] | 1627 |
|
---|
[40556] | 1628 | /**
|
---|
[40557] | 1629 | * Parses interface stability.
|
---|
| 1630 | *
|
---|
| 1631 | * @returns Interface stability if parsed correctly, otherwise error message and
|
---|
| 1632 | * kVTGStability_Invalid.
|
---|
| 1633 | * @param pStrm The stream.
|
---|
| 1634 | * @param ch The first character in the stability spec.
|
---|
| 1635 | */
|
---|
| 1636 | static kVTGStability parseStability(PSCMSTREAM pStrm, unsigned ch)
|
---|
| 1637 | {
|
---|
| 1638 | switch (ch)
|
---|
| 1639 | {
|
---|
| 1640 | case 'E':
|
---|
| 1641 | if (ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("External")))
|
---|
| 1642 | return kVTGStability_External;
|
---|
| 1643 | if (ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("Evolving")))
|
---|
| 1644 | return kVTGStability_Evolving;
|
---|
| 1645 | break;
|
---|
| 1646 | case 'I':
|
---|
| 1647 | if (ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("Internal")))
|
---|
| 1648 | return kVTGStability_Internal;
|
---|
| 1649 | break;
|
---|
| 1650 | case 'O':
|
---|
| 1651 | if (ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("Obsolete")))
|
---|
| 1652 | return kVTGStability_Obsolete;
|
---|
| 1653 | break;
|
---|
| 1654 | case 'P':
|
---|
| 1655 | if (ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("Private")))
|
---|
| 1656 | return kVTGStability_Private;
|
---|
| 1657 | break;
|
---|
| 1658 | case 'S':
|
---|
| 1659 | if (ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("Stable")))
|
---|
| 1660 | return kVTGStability_Stable;
|
---|
| 1661 | if (ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("Standard")))
|
---|
| 1662 | return kVTGStability_Standard;
|
---|
| 1663 | break;
|
---|
| 1664 | case 'U':
|
---|
| 1665 | if (ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("Unstable")))
|
---|
| 1666 | return kVTGStability_Unstable;
|
---|
| 1667 | break;
|
---|
| 1668 | }
|
---|
| 1669 | parseError(pStrm, 1, "Unknown stability specifier");
|
---|
| 1670 | return kVTGStability_Invalid;
|
---|
| 1671 | }
|
---|
| 1672 |
|
---|
| 1673 |
|
---|
| 1674 | /**
|
---|
| 1675 | * Parses data depndency class.
|
---|
| 1676 | *
|
---|
| 1677 | * @returns Data dependency class if parsed correctly, otherwise error message
|
---|
| 1678 | * and kVTGClass_Invalid.
|
---|
| 1679 | * @param pStrm The stream.
|
---|
| 1680 | * @param ch The first character in the stability spec.
|
---|
| 1681 | */
|
---|
| 1682 | static kVTGClass parseDataDepClass(PSCMSTREAM pStrm, unsigned ch)
|
---|
| 1683 | {
|
---|
| 1684 | switch (ch)
|
---|
| 1685 | {
|
---|
| 1686 | case 'C':
|
---|
| 1687 | if (ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("Common")))
|
---|
| 1688 | return kVTGClass_Common;
|
---|
| 1689 | if (ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("Cpu")))
|
---|
| 1690 | return kVTGClass_Cpu;
|
---|
| 1691 | break;
|
---|
| 1692 | case 'G':
|
---|
| 1693 | if (ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("Group")))
|
---|
| 1694 | return kVTGClass_Group;
|
---|
| 1695 | break;
|
---|
| 1696 | case 'I':
|
---|
| 1697 | if (ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("Isa")))
|
---|
| 1698 | return kVTGClass_Isa;
|
---|
| 1699 | break;
|
---|
| 1700 | case 'P':
|
---|
| 1701 | if (ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("Platform")))
|
---|
| 1702 | return kVTGClass_Platform;
|
---|
| 1703 | break;
|
---|
| 1704 | case 'U':
|
---|
| 1705 | if (ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("Unknown")))
|
---|
| 1706 | return kVTGClass_Unknown;
|
---|
| 1707 | break;
|
---|
| 1708 | }
|
---|
| 1709 | parseError(pStrm, 1, "Unknown data dependency class specifier");
|
---|
| 1710 | return kVTGClass_Invalid;
|
---|
| 1711 | }
|
---|
| 1712 |
|
---|
| 1713 | /**
|
---|
| 1714 | * Parses a pragma D attributes statement.
|
---|
| 1715 | *
|
---|
| 1716 | * @returns Suitable exit code, errors message already written on failure.
|
---|
| 1717 | * @param pStrm The stream.
|
---|
| 1718 | */
|
---|
| 1719 | static RTEXITCODE parsePragmaDAttributes(PSCMSTREAM pStrm)
|
---|
| 1720 | {
|
---|
| 1721 | /*
|
---|
| 1722 | * "CodeStability/DataStability/DataDepClass" - no spaces allowed.
|
---|
| 1723 | */
|
---|
| 1724 | unsigned ch = parseGetNextNonSpaceNonCommentChOnPpLine(pStrm);
|
---|
| 1725 | if (ch == ~(unsigned)0)
|
---|
| 1726 | return RTEXITCODE_FAILURE;
|
---|
| 1727 |
|
---|
| 1728 | kVTGStability enmCode = parseStability(pStrm, ch);
|
---|
| 1729 | if (enmCode == kVTGStability_Invalid)
|
---|
| 1730 | return RTEXITCODE_FAILURE;
|
---|
| 1731 | ch = ScmStreamGetCh(pStrm);
|
---|
| 1732 | if (ch != '/')
|
---|
| 1733 | return parseError(pStrm, 1, "Expected '/' following the code stability specifier");
|
---|
| 1734 |
|
---|
| 1735 | kVTGStability enmData = parseStability(pStrm, ScmStreamGetCh(pStrm));
|
---|
| 1736 | if (enmData == kVTGStability_Invalid)
|
---|
| 1737 | return RTEXITCODE_FAILURE;
|
---|
| 1738 | ch = ScmStreamGetCh(pStrm);
|
---|
| 1739 | if (ch != '/')
|
---|
| 1740 | return parseError(pStrm, 1, "Expected '/' following the data stability specifier");
|
---|
| 1741 |
|
---|
| 1742 | kVTGClass enmDataDep = parseDataDepClass(pStrm, ScmStreamGetCh(pStrm));
|
---|
| 1743 | if (enmDataDep == kVTGClass_Invalid)
|
---|
| 1744 | return RTEXITCODE_FAILURE;
|
---|
| 1745 |
|
---|
| 1746 | /*
|
---|
| 1747 | * Expecting 'provider' followed by the name of an provider defined earlier.
|
---|
| 1748 | */
|
---|
| 1749 | ch = parseGetNextNonSpaceNonCommentChOnPpLine(pStrm);
|
---|
| 1750 | if (ch == ~(unsigned)0)
|
---|
| 1751 | return RTEXITCODE_FAILURE;
|
---|
| 1752 | if (ch != 'p' || !ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("provider")))
|
---|
| 1753 | return parseError(pStrm, 1, "Expected 'provider'");
|
---|
| 1754 |
|
---|
| 1755 | size_t cchName;
|
---|
| 1756 | const char *pszName = parseGetNextCWord(pStrm, &cchName);
|
---|
| 1757 | if (!pszName)
|
---|
| 1758 | return parseError(pStrm, 1, "Expected provider name");
|
---|
| 1759 |
|
---|
| 1760 | PVTGPROVIDER pProv;
|
---|
| 1761 | RTListForEach(&g_ProviderHead, pProv, VTGPROVIDER, ListEntry)
|
---|
| 1762 | {
|
---|
| 1763 | if ( !strncmp(pProv->pszName, pszName, cchName)
|
---|
| 1764 | && pProv->pszName[cchName] == '\0')
|
---|
| 1765 | break;
|
---|
| 1766 | }
|
---|
[40594] | 1767 | if (RTListNodeIsDummy(&g_ProviderHead, pProv, VTGPROVIDER, ListEntry))
|
---|
[40557] | 1768 | return parseError(pStrm, cchName, "Provider not found");
|
---|
| 1769 |
|
---|
| 1770 | /*
|
---|
| 1771 | * Which aspect of the provider?
|
---|
| 1772 | */
|
---|
| 1773 | size_t cchAspect;
|
---|
| 1774 | const char *pszAspect = parseGetNextCWord(pStrm, &cchAspect);
|
---|
| 1775 | if (!pszAspect)
|
---|
| 1776 | return parseError(pStrm, 1, "Expected provider aspect");
|
---|
| 1777 |
|
---|
| 1778 | PVTGATTRS pAttrs;
|
---|
| 1779 | if (cchAspect == 8 && !memcmp(pszAspect, "provider", 8))
|
---|
| 1780 | pAttrs = &pProv->AttrSelf;
|
---|
| 1781 | else if (cchAspect == 8 && !memcmp(pszAspect, "function", 8))
|
---|
| 1782 | pAttrs = &pProv->AttrFunctions;
|
---|
| 1783 | else if (cchAspect == 6 && !memcmp(pszAspect, "module", 6))
|
---|
| 1784 | pAttrs = &pProv->AttrModules;
|
---|
| 1785 | else if (cchAspect == 4 && !memcmp(pszAspect, "name", 4))
|
---|
| 1786 | pAttrs = &pProv->AttrName;
|
---|
| 1787 | else if (cchAspect == 4 && !memcmp(pszAspect, "args", 4))
|
---|
| 1788 | pAttrs = &pProv->AttrArguments;
|
---|
| 1789 | else
|
---|
| 1790 | return parseError(pStrm, cchAspect, "Unknown aspect");
|
---|
| 1791 |
|
---|
| 1792 | if (pAttrs->enmCode != kVTGStability_Invalid)
|
---|
| 1793 | return parseError(pStrm, cchAspect, "You have already specified these attributes");
|
---|
| 1794 |
|
---|
| 1795 | pAttrs->enmCode = enmCode;
|
---|
| 1796 | pAttrs->enmData = enmData;
|
---|
| 1797 | pAttrs->enmDataDep = enmDataDep;
|
---|
| 1798 | return RTEXITCODE_SUCCESS;
|
---|
| 1799 | }
|
---|
| 1800 |
|
---|
| 1801 | /**
|
---|
| 1802 | * Parses a D pragma statement.
|
---|
| 1803 | *
|
---|
| 1804 | * @returns Suitable exit code, errors message already written on failure.
|
---|
| 1805 | * @param pStrm The stream.
|
---|
| 1806 | */
|
---|
| 1807 | static RTEXITCODE parsePragma(PSCMSTREAM pStrm)
|
---|
| 1808 | {
|
---|
| 1809 | RTEXITCODE rcExit;
|
---|
| 1810 | unsigned ch = parseGetNextNonSpaceNonCommentChOnPpLine(pStrm);
|
---|
| 1811 | if (ch == ~(unsigned)0)
|
---|
| 1812 | rcExit = RTEXITCODE_FAILURE;
|
---|
| 1813 | else if (ch == 'D' && ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("D")))
|
---|
| 1814 | {
|
---|
| 1815 | ch = parseGetNextNonSpaceNonCommentChOnPpLine(pStrm);
|
---|
| 1816 | if (ch == ~(unsigned)0)
|
---|
| 1817 | rcExit = RTEXITCODE_FAILURE;
|
---|
| 1818 | else if (ch == 'a' && ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("attributes")))
|
---|
| 1819 | rcExit = parsePragmaDAttributes(pStrm);
|
---|
| 1820 | else
|
---|
| 1821 | rcExit = parseError(pStrm, 1, "Unknown pragma D");
|
---|
| 1822 | }
|
---|
| 1823 | else
|
---|
| 1824 | rcExit = parseError(pStrm, 1, "Unknown pragma");
|
---|
| 1825 | return rcExit;
|
---|
| 1826 | }
|
---|
| 1827 |
|
---|
| 1828 |
|
---|
| 1829 | /**
|
---|
[40878] | 1830 | * Classifies the given type expression.
|
---|
| 1831 | *
|
---|
| 1832 | * @return Type flags.
|
---|
| 1833 | * @param pszType The type expression.
|
---|
[88956] | 1834 | * @param pStrm The input stream (for errors + warnings).
|
---|
| 1835 | * @param offSrc The absolute source position of this expression (for
|
---|
| 1836 | * warnings).
|
---|
[40878] | 1837 | */
|
---|
[88956] | 1838 | static uint32_t parseTypeExpression(const char *pszType, PSCMSTREAM pStrm, size_t offSrc)
|
---|
[40878] | 1839 | {
|
---|
| 1840 | size_t cchType = strlen(pszType);
|
---|
| 1841 | #define MY_STRMATCH(a_sz) (cchType == sizeof(a_sz) - 1 && !memcmp(a_sz, pszType, sizeof(a_sz) - 1))
|
---|
| 1842 |
|
---|
| 1843 | /*
|
---|
| 1844 | * Try detect pointers.
|
---|
| 1845 | */
|
---|
[54067] | 1846 | if (pszType[cchType - 1] == '*')
|
---|
| 1847 | {
|
---|
| 1848 | if (MY_STRMATCH("const char *")) return VTG_TYPE_POINTER | VTG_TYPE_CONST_CHAR_PTR;
|
---|
| 1849 | return VTG_TYPE_POINTER;
|
---|
| 1850 | }
|
---|
[40878] | 1851 | if (pszType[cchType - 1] == '&')
|
---|
| 1852 | {
|
---|
[88956] | 1853 | parseWarnAbs(pStrm, offSrc, "Please avoid using references like '%s' for probe arguments!", pszType);
|
---|
[40878] | 1854 | return VTG_TYPE_POINTER;
|
---|
| 1855 | }
|
---|
| 1856 |
|
---|
| 1857 | /*
|
---|
| 1858 | * Standard integer types and IPRT variants.
|
---|
| 1859 | * It's important that we catch all types larger than 32-bit here or we'll
|
---|
| 1860 | * screw up the probe argument handling.
|
---|
| 1861 | */
|
---|
[40882] | 1862 | if (MY_STRMATCH("int")) return VTG_TYPE_FIXED_SIZED | sizeof(int) | VTG_TYPE_SIGNED;
|
---|
| 1863 | if (MY_STRMATCH("uintptr_t")) return VTG_TYPE_HC_ARCH_SIZED | VTG_TYPE_UNSIGNED;
|
---|
| 1864 | if (MY_STRMATCH("intptr_t")) return VTG_TYPE_HC_ARCH_SIZED | VTG_TYPE_SIGNED;
|
---|
| 1865 |
|
---|
[40878] | 1866 | //if (MY_STRMATCH("uint128_t")) return VTG_TYPE_FIXED_SIZED | sizeof(uint128_t) | VTG_TYPE_UNSIGNED;
|
---|
| 1867 | if (MY_STRMATCH("uint64_t")) return VTG_TYPE_FIXED_SIZED | sizeof(uint64_t) | VTG_TYPE_UNSIGNED;
|
---|
| 1868 | if (MY_STRMATCH("uint32_t")) return VTG_TYPE_FIXED_SIZED | sizeof(uint32_t) | VTG_TYPE_UNSIGNED;
|
---|
| 1869 | if (MY_STRMATCH("uint16_t")) return VTG_TYPE_FIXED_SIZED | sizeof(uint16_t) | VTG_TYPE_UNSIGNED;
|
---|
| 1870 | if (MY_STRMATCH("uint8_t")) return VTG_TYPE_FIXED_SIZED | sizeof(uint8_t) | VTG_TYPE_UNSIGNED;
|
---|
| 1871 |
|
---|
| 1872 | //if (MY_STRMATCH("int128_t")) return VTG_TYPE_FIXED_SIZED | sizeof(int128_t) | VTG_TYPE_SIGNED;
|
---|
| 1873 | if (MY_STRMATCH("int64_t")) return VTG_TYPE_FIXED_SIZED | sizeof(int64_t) | VTG_TYPE_SIGNED;
|
---|
| 1874 | if (MY_STRMATCH("int32_t")) return VTG_TYPE_FIXED_SIZED | sizeof(int32_t) | VTG_TYPE_SIGNED;
|
---|
| 1875 | if (MY_STRMATCH("int16_t")) return VTG_TYPE_FIXED_SIZED | sizeof(int16_t) | VTG_TYPE_SIGNED;
|
---|
| 1876 | if (MY_STRMATCH("int8_t")) return VTG_TYPE_FIXED_SIZED | sizeof(int8_t) | VTG_TYPE_SIGNED;
|
---|
| 1877 |
|
---|
| 1878 | if (MY_STRMATCH("RTUINT64U")) return VTG_TYPE_FIXED_SIZED | sizeof(uint64_t) | VTG_TYPE_UNSIGNED;
|
---|
| 1879 | if (MY_STRMATCH("RTUINT32U")) return VTG_TYPE_FIXED_SIZED | sizeof(uint32_t) | VTG_TYPE_UNSIGNED;
|
---|
| 1880 | if (MY_STRMATCH("RTUINT16U")) return VTG_TYPE_FIXED_SIZED | sizeof(uint16_t) | VTG_TYPE_UNSIGNED;
|
---|
| 1881 |
|
---|
| 1882 | if (MY_STRMATCH("RTMSINTERVAL")) return VTG_TYPE_FIXED_SIZED | sizeof(RTMSINTERVAL) | VTG_TYPE_UNSIGNED;
|
---|
| 1883 | if (MY_STRMATCH("RTTIMESPEC")) return VTG_TYPE_FIXED_SIZED | sizeof(RTTIMESPEC) | VTG_TYPE_SIGNED;
|
---|
[40882] | 1884 | if (MY_STRMATCH("RTPROCESS")) return VTG_TYPE_FIXED_SIZED | sizeof(RTPROCESS) | VTG_TYPE_UNSIGNED;
|
---|
[40878] | 1885 | if (MY_STRMATCH("RTHCPHYS")) return VTG_TYPE_FIXED_SIZED | sizeof(RTHCPHYS) | VTG_TYPE_UNSIGNED | VTG_TYPE_PHYS;
|
---|
| 1886 |
|
---|
| 1887 | if (MY_STRMATCH("RTR3PTR")) return VTG_TYPE_CTX_POINTER | VTG_TYPE_CTX_R3;
|
---|
| 1888 | if (MY_STRMATCH("RTR0PTR")) return VTG_TYPE_CTX_POINTER | VTG_TYPE_CTX_R0;
|
---|
| 1889 | if (MY_STRMATCH("RTRCPTR")) return VTG_TYPE_CTX_POINTER | VTG_TYPE_CTX_RC;
|
---|
| 1890 | if (MY_STRMATCH("RTHCPTR")) return VTG_TYPE_CTX_POINTER | VTG_TYPE_CTX_R3 | VTG_TYPE_CTX_R0;
|
---|
| 1891 |
|
---|
| 1892 | if (MY_STRMATCH("RTR3UINTPTR")) return VTG_TYPE_CTX_POINTER | VTG_TYPE_CTX_R3 | VTG_TYPE_UNSIGNED;
|
---|
| 1893 | if (MY_STRMATCH("RTR0UINTPTR")) return VTG_TYPE_CTX_POINTER | VTG_TYPE_CTX_R0 | VTG_TYPE_UNSIGNED;
|
---|
| 1894 | if (MY_STRMATCH("RTRCUINTPTR")) return VTG_TYPE_CTX_POINTER | VTG_TYPE_CTX_RC | VTG_TYPE_UNSIGNED;
|
---|
| 1895 | if (MY_STRMATCH("RTHCUINTPTR")) return VTG_TYPE_CTX_POINTER | VTG_TYPE_CTX_R3 | VTG_TYPE_CTX_R0 | VTG_TYPE_UNSIGNED;
|
---|
| 1896 |
|
---|
| 1897 | if (MY_STRMATCH("RTR3INTPTR")) return VTG_TYPE_CTX_POINTER | VTG_TYPE_CTX_R3 | VTG_TYPE_SIGNED;
|
---|
| 1898 | if (MY_STRMATCH("RTR0INTPTR")) return VTG_TYPE_CTX_POINTER | VTG_TYPE_CTX_R0 | VTG_TYPE_SIGNED;
|
---|
| 1899 | if (MY_STRMATCH("RTRCINTPTR")) return VTG_TYPE_CTX_POINTER | VTG_TYPE_CTX_RC | VTG_TYPE_SIGNED;
|
---|
| 1900 | if (MY_STRMATCH("RTHCINTPTR")) return VTG_TYPE_CTX_POINTER | VTG_TYPE_CTX_R3 | VTG_TYPE_CTX_R0 | VTG_TYPE_SIGNED;
|
---|
| 1901 |
|
---|
| 1902 | if (MY_STRMATCH("RTUINTPTR")) return VTG_TYPE_CTX_POINTER | VTG_TYPE_CTX_R3 | VTG_TYPE_CTX_R0 | VTG_TYPE_CTX_RC | VTG_TYPE_UNSIGNED;
|
---|
| 1903 | if (MY_STRMATCH("RTINTPTR")) return VTG_TYPE_CTX_POINTER | VTG_TYPE_CTX_R3 | VTG_TYPE_CTX_R0 | VTG_TYPE_CTX_RC | VTG_TYPE_SIGNED;
|
---|
| 1904 |
|
---|
| 1905 | if (MY_STRMATCH("RTHCUINTREG")) return VTG_TYPE_HC_ARCH_SIZED | VTG_TYPE_CTX_R3 | VTG_TYPE_CTX_R0 | VTG_TYPE_UNSIGNED;
|
---|
| 1906 | if (MY_STRMATCH("RTR3UINTREG")) return VTG_TYPE_HC_ARCH_SIZED | VTG_TYPE_CTX_R3 | VTG_TYPE_UNSIGNED;
|
---|
| 1907 | if (MY_STRMATCH("RTR0UINTREG")) return VTG_TYPE_HC_ARCH_SIZED | VTG_TYPE_CTX_R3 | VTG_TYPE_UNSIGNED;
|
---|
| 1908 |
|
---|
| 1909 | if (MY_STRMATCH("RTGCUINTREG")) return VTG_TYPE_FIXED_SIZED | sizeof(RTGCUINTREG) | VTG_TYPE_UNSIGNED | VTG_TYPE_CTX_GST;
|
---|
| 1910 | if (MY_STRMATCH("RTGCPTR")) return VTG_TYPE_FIXED_SIZED | sizeof(RTGCPTR) | VTG_TYPE_UNSIGNED | VTG_TYPE_CTX_GST;
|
---|
| 1911 | if (MY_STRMATCH("RTGCINTPTR")) return VTG_TYPE_FIXED_SIZED | sizeof(RTGCUINTPTR) | VTG_TYPE_SIGNED | VTG_TYPE_CTX_GST;
|
---|
| 1912 | if (MY_STRMATCH("RTGCPTR32")) return VTG_TYPE_FIXED_SIZED | sizeof(RTGCPTR32) | VTG_TYPE_SIGNED | VTG_TYPE_CTX_GST;
|
---|
| 1913 | if (MY_STRMATCH("RTGCPTR64")) return VTG_TYPE_FIXED_SIZED | sizeof(RTGCPTR64) | VTG_TYPE_SIGNED | VTG_TYPE_CTX_GST;
|
---|
| 1914 | if (MY_STRMATCH("RTGCPHYS")) return VTG_TYPE_FIXED_SIZED | sizeof(RTGCPHYS) | VTG_TYPE_UNSIGNED | VTG_TYPE_PHYS | VTG_TYPE_CTX_GST;
|
---|
| 1915 | if (MY_STRMATCH("RTGCPHYS32")) return VTG_TYPE_FIXED_SIZED | sizeof(RTGCPHYS32) | VTG_TYPE_UNSIGNED | VTG_TYPE_PHYS | VTG_TYPE_CTX_GST;
|
---|
| 1916 | if (MY_STRMATCH("RTGCPHYS64")) return VTG_TYPE_FIXED_SIZED | sizeof(RTGCPHYS64) | VTG_TYPE_UNSIGNED | VTG_TYPE_PHYS | VTG_TYPE_CTX_GST;
|
---|
| 1917 |
|
---|
| 1918 | /*
|
---|
| 1919 | * The special VBox types.
|
---|
| 1920 | */
|
---|
[41338] | 1921 | if (MY_STRMATCH("PVM")) return VTG_TYPE_POINTER;
|
---|
| 1922 | if (MY_STRMATCH("PVMCPU")) return VTG_TYPE_POINTER;
|
---|
| 1923 | if (MY_STRMATCH("PCPUMCTX")) return VTG_TYPE_POINTER;
|
---|
[40878] | 1924 |
|
---|
| 1925 | /*
|
---|
| 1926 | * Preaching time.
|
---|
| 1927 | */
|
---|
| 1928 | if ( MY_STRMATCH("unsigned long")
|
---|
| 1929 | || MY_STRMATCH("unsigned long long")
|
---|
| 1930 | || MY_STRMATCH("signed long")
|
---|
| 1931 | || MY_STRMATCH("signed long long")
|
---|
| 1932 | || MY_STRMATCH("long")
|
---|
| 1933 | || MY_STRMATCH("long long")
|
---|
| 1934 | || MY_STRMATCH("char")
|
---|
| 1935 | || MY_STRMATCH("signed char")
|
---|
| 1936 | || MY_STRMATCH("unsigned char")
|
---|
| 1937 | || MY_STRMATCH("double")
|
---|
| 1938 | || MY_STRMATCH("long double")
|
---|
| 1939 | || MY_STRMATCH("float")
|
---|
| 1940 | )
|
---|
| 1941 | {
|
---|
| 1942 | RTMsgError("Please do NOT use the type '%s' for probe arguments!", pszType);
|
---|
| 1943 | g_cTypeErrors++;
|
---|
| 1944 | return 0;
|
---|
| 1945 | }
|
---|
| 1946 |
|
---|
| 1947 | if ( MY_STRMATCH("unsigned")
|
---|
| 1948 | || MY_STRMATCH("signed")
|
---|
| 1949 | || MY_STRMATCH("signed int")
|
---|
| 1950 | || MY_STRMATCH("unsigned int")
|
---|
| 1951 | || MY_STRMATCH("short")
|
---|
| 1952 | || MY_STRMATCH("signed short")
|
---|
| 1953 | || MY_STRMATCH("unsigned short")
|
---|
| 1954 | )
|
---|
[88956] | 1955 | parseWarnAbs(pStrm, offSrc, "Please avoid using the type '%s' for probe arguments!", pszType);
|
---|
[40878] | 1956 | if (MY_STRMATCH("unsigned")) return VTG_TYPE_FIXED_SIZED | sizeof(int) | VTG_TYPE_UNSIGNED;
|
---|
| 1957 | if (MY_STRMATCH("unsigned int")) return VTG_TYPE_FIXED_SIZED | sizeof(int) | VTG_TYPE_UNSIGNED;
|
---|
| 1958 | if (MY_STRMATCH("signed")) return VTG_TYPE_FIXED_SIZED | sizeof(int) | VTG_TYPE_SIGNED;
|
---|
| 1959 | if (MY_STRMATCH("signed int")) return VTG_TYPE_FIXED_SIZED | sizeof(int) | VTG_TYPE_SIGNED;
|
---|
| 1960 | if (MY_STRMATCH("short")) return VTG_TYPE_FIXED_SIZED | sizeof(short) | VTG_TYPE_SIGNED;
|
---|
| 1961 | if (MY_STRMATCH("signed short")) return VTG_TYPE_FIXED_SIZED | sizeof(short) | VTG_TYPE_SIGNED;
|
---|
| 1962 | if (MY_STRMATCH("unsigned short")) return VTG_TYPE_FIXED_SIZED | sizeof(short) | VTG_TYPE_UNSIGNED;
|
---|
| 1963 |
|
---|
| 1964 | /*
|
---|
| 1965 | * What we haven't caught by now is either unknown to us or wrong.
|
---|
| 1966 | */
|
---|
| 1967 | if (pszType[0] == 'P')
|
---|
| 1968 | {
|
---|
| 1969 | RTMsgError("Type '%s' looks like a pointer typedef, please do NOT use those "
|
---|
| 1970 | "but rather the non-pointer typedef or struct with '*'",
|
---|
| 1971 | pszType);
|
---|
| 1972 | g_cTypeErrors++;
|
---|
| 1973 | return VTG_TYPE_POINTER;
|
---|
| 1974 | }
|
---|
| 1975 |
|
---|
| 1976 | RTMsgError("Don't know '%s' - please change or fix VBoxTpG", pszType);
|
---|
| 1977 | g_cTypeErrors++;
|
---|
| 1978 |
|
---|
| 1979 | #undef MY_STRCMP
|
---|
| 1980 | return 0;
|
---|
| 1981 | }
|
---|
| 1982 |
|
---|
| 1983 |
|
---|
| 1984 | /**
|
---|
[41338] | 1985 | * Initializes the members of an argument.
|
---|
| 1986 | *
|
---|
| 1987 | * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE+msg.
|
---|
| 1988 | * @param pProbe The probe.
|
---|
| 1989 | * @param pArg The argument.
|
---|
[88956] | 1990 | * @param pStrm The input stream (for errors + warnings).
|
---|
[41338] | 1991 | * @param pchType The type.
|
---|
| 1992 | * @param cchType The type length.
|
---|
| 1993 | * @param pchName The name.
|
---|
| 1994 | * @param cchName The name length.
|
---|
| 1995 | */
|
---|
| 1996 | static RTEXITCODE parseInitArgument(PVTGPROBE pProbe, PVTGARG pArg, PSCMSTREAM pStrm,
|
---|
| 1997 | char *pchType, size_t cchType, char *pchName, size_t cchName)
|
---|
| 1998 | {
|
---|
| 1999 | Assert(!pArg->pszName); Assert(!pArg->pszTracerType); Assert(!pArg->pszCtxType); Assert(!pArg->fType);
|
---|
| 2000 |
|
---|
| 2001 | pArg->pszArgPassingFmt = ", %s";
|
---|
| 2002 | pArg->pszName = RTStrDupN(pchName, cchName);
|
---|
| 2003 | pArg->pszTracerType = strtabInsertN(pchType, cchType);
|
---|
| 2004 | if (!pArg->pszTracerType || !pArg->pszName)
|
---|
| 2005 | return parseError(pStrm, 1, "Out of memory");
|
---|
[88956] | 2006 | pArg->fType = parseTypeExpression(pArg->pszTracerType, pStrm, pArg->offSrc);
|
---|
[41338] | 2007 |
|
---|
| 2008 | if ( (pArg->fType & VTG_TYPE_POINTER)
|
---|
| 2009 | && !(g_fTypeContext & VTG_TYPE_CTX_R0) )
|
---|
| 2010 | {
|
---|
| 2011 | pArg->fType &= ~VTG_TYPE_POINTER;
|
---|
| 2012 | if ( !strcmp(pArg->pszTracerType, "struct VM *") || !strcmp(pArg->pszTracerType, "PVM")
|
---|
| 2013 | || !strcmp(pArg->pszTracerType, "struct VMCPU *") || !strcmp(pArg->pszTracerType, "PVMCPU")
|
---|
| 2014 | || !strcmp(pArg->pszTracerType, "struct CPUMCTX *") || !strcmp(pArg->pszTracerType, "PCPUMCTX")
|
---|
| 2015 | )
|
---|
| 2016 | {
|
---|
| 2017 | pArg->fType |= VTG_TYPE_CTX_POINTER | VTG_TYPE_CTX_R0
|
---|
| 2018 | | VTG_TYPE_FIXED_SIZED | (g_cHostBits / 8)
|
---|
| 2019 | | VTG_TYPE_AUTO_CONV_PTR;
|
---|
| 2020 | pArg->pszCtxType = RTStrDup("RTR0PTR");
|
---|
| 2021 |
|
---|
| 2022 | if (!strcmp(pArg->pszTracerType, "struct VM *") || !strcmp(pArg->pszTracerType, "PVM"))
|
---|
| 2023 | pArg->pszArgPassingFmt = ", VTG_VM_TO_R0(%s)";
|
---|
| 2024 | else if (!strcmp(pArg->pszTracerType, "struct VMCPU *") || !strcmp(pArg->pszTracerType, "PVMCPU"))
|
---|
| 2025 | pArg->pszArgPassingFmt = ", VTG_VMCPU_TO_R0(%s)";
|
---|
| 2026 | else
|
---|
| 2027 | {
|
---|
| 2028 | PVTGARG pFirstArg = RTListGetFirst(&pProbe->ArgHead, VTGARG, ListEntry);
|
---|
| 2029 | if ( !pFirstArg
|
---|
| 2030 | || pFirstArg == pArg
|
---|
| 2031 | || strcmp(pFirstArg->pszName, "a_pVCpu")
|
---|
| 2032 | || ( strcmp(pFirstArg->pszTracerType, "struct VMCPU *")
|
---|
| 2033 | && strcmp(pFirstArg->pszTracerType, "PVMCPU *")) )
|
---|
| 2034 | return parseError(pStrm, 1, "The automatic ring-0 pointer conversion requires 'a_pVCpu' with type 'struct VMCPU *' as the first argument");
|
---|
| 2035 |
|
---|
| 2036 | if (!strcmp(pArg->pszTracerType, "struct CPUMCTX *")|| !strcmp(pArg->pszTracerType, "PCPUMCTX"))
|
---|
| 2037 | pArg->pszArgPassingFmt = ", VTG_CPUMCTX_TO_R0(a_pVCpu, %s)";
|
---|
| 2038 | else
|
---|
| 2039 | pArg->pszArgPassingFmt = ", VBoxTpG-Is-Buggy!!";
|
---|
| 2040 | }
|
---|
| 2041 | }
|
---|
| 2042 | else
|
---|
| 2043 | {
|
---|
| 2044 | pArg->fType |= VTG_TYPE_CTX_POINTER | g_fTypeContext | VTG_TYPE_FIXED_SIZED | (g_cBits / 8);
|
---|
| 2045 | pArg->pszCtxType = RTStrDupN(pchType, cchType);
|
---|
| 2046 | }
|
---|
| 2047 | }
|
---|
| 2048 | else
|
---|
| 2049 | pArg->pszCtxType = RTStrDupN(pchType, cchType);
|
---|
| 2050 | if (!pArg->pszCtxType)
|
---|
| 2051 | return parseError(pStrm, 1, "Out of memory");
|
---|
| 2052 |
|
---|
| 2053 | return RTEXITCODE_SUCCESS;
|
---|
| 2054 | }
|
---|
| 2055 |
|
---|
| 2056 |
|
---|
| 2057 | /**
|
---|
[40641] | 2058 | * Unmangles the probe name.
|
---|
| 2059 | *
|
---|
[40619] | 2060 | * This involves translating double underscore to dash.
|
---|
[40641] | 2061 | *
|
---|
[40619] | 2062 | * @returns Pointer to the unmangled name in the string table.
|
---|
| 2063 | * @param pszMangled The mangled name.
|
---|
| 2064 | */
|
---|
| 2065 | static const char *parseUnmangleProbeName(const char *pszMangled)
|
---|
| 2066 | {
|
---|
| 2067 | size_t cchMangled = strlen(pszMangled);
|
---|
| 2068 | char *pszTmp = (char *)alloca(cchMangled + 2);
|
---|
| 2069 | const char *pszSrc = pszMangled;
|
---|
| 2070 | char *pszDst = pszTmp;
|
---|
| 2071 |
|
---|
| 2072 | while (*pszSrc)
|
---|
| 2073 | {
|
---|
| 2074 | if (pszSrc[0] == '_' && pszSrc[1] == '_' && pszSrc[2] != '_')
|
---|
| 2075 | {
|
---|
| 2076 | *pszDst++ = '-';
|
---|
| 2077 | pszSrc += 2;
|
---|
| 2078 | }
|
---|
| 2079 | else
|
---|
| 2080 | *pszDst++ = *pszSrc++;
|
---|
| 2081 | }
|
---|
| 2082 | *pszDst = '\0';
|
---|
| 2083 |
|
---|
| 2084 | return strtabInsertN(pszTmp, pszDst - pszTmp);
|
---|
| 2085 | }
|
---|
| 2086 |
|
---|
| 2087 |
|
---|
| 2088 | /**
|
---|
[40556] | 2089 | * Parses a D probe statement.
|
---|
| 2090 | *
|
---|
| 2091 | * @returns Suitable exit code, errors message already written on failure.
|
---|
| 2092 | * @param pStrm The stream.
|
---|
[40557] | 2093 | * @param pProv The provider being parsed.
|
---|
[40556] | 2094 | */
|
---|
| 2095 | static RTEXITCODE parseProbe(PSCMSTREAM pStrm, PVTGPROVIDER pProv)
|
---|
| 2096 | {
|
---|
[88956] | 2097 | size_t const iProbeLine = ScmStreamTellLine(pStrm);
|
---|
| 2098 |
|
---|
[40556] | 2099 | /*
|
---|
| 2100 | * Next up is a name followed by an opening parenthesis.
|
---|
| 2101 | */
|
---|
| 2102 | size_t cchProbe;
|
---|
| 2103 | const char *pszProbe = parseGetNextCWord(pStrm, &cchProbe);
|
---|
| 2104 | if (!pszProbe)
|
---|
| 2105 | return parseError(pStrm, 1, "Expected a probe name starting with an alphabetical character");
|
---|
| 2106 | unsigned ch = parseGetNextNonSpaceNonCommentCh(pStrm);
|
---|
| 2107 | if (ch != '(')
|
---|
| 2108 | return parseError(pStrm, 1, "Expected '(' after the probe name");
|
---|
| 2109 |
|
---|
| 2110 | /*
|
---|
| 2111 | * Create a probe instance.
|
---|
| 2112 | */
|
---|
| 2113 | PVTGPROBE pProbe = (PVTGPROBE)RTMemAllocZ(sizeof(*pProbe));
|
---|
| 2114 | if (!pProbe)
|
---|
| 2115 | return parseError(pStrm, 0, "Out of memory");
|
---|
[40557] | 2116 | RTListInit(&pProbe->ArgHead);
|
---|
[40556] | 2117 | RTListAppend(&pProv->ProbeHead, &pProbe->ListEntry);
|
---|
[40884] | 2118 | pProbe->offArgList = UINT32_MAX;
|
---|
[88956] | 2119 | pProbe->iLine = iProbeLine;
|
---|
[40619] | 2120 | pProbe->pszMangledName = RTStrDupN(pszProbe, cchProbe);
|
---|
| 2121 | if (!pProbe->pszMangledName)
|
---|
[40556] | 2122 | return parseError(pStrm, 0, "Out of memory");
|
---|
[40619] | 2123 | pProbe->pszUnmangledName = parseUnmangleProbeName(pProbe->pszMangledName);
|
---|
| 2124 | if (!pProbe->pszUnmangledName)
|
---|
| 2125 | return parseError(pStrm, 0, "Out of memory");
|
---|
[40641] | 2126 |
|
---|
[40556] | 2127 | /*
|
---|
[40557] | 2128 | * Parse loop for the argument.
|
---|
[40556] | 2129 | */
|
---|
[40557] | 2130 | PVTGARG pArg = NULL;
|
---|
| 2131 | size_t cchName = 0;
|
---|
[40569] | 2132 | size_t cchArg = 0;
|
---|
| 2133 | char szArg[4096];
|
---|
[40556] | 2134 | for (;;)
|
---|
| 2135 | {
|
---|
| 2136 | ch = parseGetNextNonSpaceNonCommentCh(pStrm);
|
---|
| 2137 | switch (ch)
|
---|
| 2138 | {
|
---|
| 2139 | case ')':
|
---|
| 2140 | case ',':
|
---|
| 2141 | {
|
---|
[40557] | 2142 | /* commit the argument */
|
---|
| 2143 | if (pArg)
|
---|
[40556] | 2144 | {
|
---|
[40557] | 2145 | if (!cchName)
|
---|
| 2146 | return parseError(pStrm, 1, "Argument has no name");
|
---|
[40604] | 2147 | if (cchArg - cchName - 1 >= 128)
|
---|
| 2148 | return parseError(pStrm, 1, "Argument type too long");
|
---|
[41338] | 2149 | RTEXITCODE rcExit = parseInitArgument(pProbe, pArg, pStrm,
|
---|
| 2150 | szArg, cchArg - cchName - 1,
|
---|
| 2151 | &szArg[cchArg - cchName], cchName);
|
---|
| 2152 | if (rcExit != RTEXITCODE_SUCCESS)
|
---|
| 2153 | return rcExit;
|
---|
[40878] | 2154 | if (VTG_TYPE_IS_LARGE(pArg->fType))
|
---|
| 2155 | pProbe->fHaveLargeArgs = true;
|
---|
[40557] | 2156 | pArg = NULL;
|
---|
[40569] | 2157 | cchName = cchArg = 0;
|
---|
[40556] | 2158 | }
|
---|
[40557] | 2159 | if (ch == ')')
|
---|
[40556] | 2160 | {
|
---|
[40557] | 2161 | size_t off = ScmStreamTell(pStrm);
|
---|
| 2162 | ch = parseGetNextNonSpaceNonCommentCh(pStrm);
|
---|
| 2163 | if (ch != ';')
|
---|
| 2164 | return parseErrorAbs(pStrm, off, "Expected ';'");
|
---|
| 2165 | return RTEXITCODE_SUCCESS;
|
---|
[40556] | 2166 | }
|
---|
| 2167 | break;
|
---|
| 2168 | }
|
---|
| 2169 |
|
---|
| 2170 | default:
|
---|
| 2171 | {
|
---|
| 2172 | size_t cchWord;
|
---|
| 2173 | const char *pszWord = ScmStreamCGetWordM1(pStrm, &cchWord);
|
---|
| 2174 | if (!pszWord)
|
---|
[40557] | 2175 | return parseError(pStrm, 0, "Expected argument");
|
---|
| 2176 | if (!pArg)
|
---|
| 2177 | {
|
---|
| 2178 | pArg = (PVTGARG)RTMemAllocZ(sizeof(*pArg));
|
---|
| 2179 | if (!pArg)
|
---|
| 2180 | return parseError(pStrm, 1, "Out of memory");
|
---|
| 2181 | RTListAppend(&pProbe->ArgHead, &pArg->ListEntry);
|
---|
[88956] | 2182 | pArg->iArgNo = pProbe->cArgs++;
|
---|
| 2183 | pArg->pProbe = pProbe;
|
---|
| 2184 | pArg->offSrc = ScmStreamTell(pStrm) - cchWord;
|
---|
[40557] | 2185 |
|
---|
[40569] | 2186 | if (cchWord + 1 > sizeof(szArg))
|
---|
| 2187 | return parseError(pStrm, 1, "Too long parameter declaration");
|
---|
| 2188 | memcpy(szArg, pszWord, cchWord);
|
---|
| 2189 | szArg[cchWord] = '\0';
|
---|
| 2190 | cchArg = cchWord;
|
---|
[40557] | 2191 | cchName = 0;
|
---|
| 2192 | }
|
---|
[40556] | 2193 | else
|
---|
[40557] | 2194 | {
|
---|
[40569] | 2195 | if (cchArg + 1 + cchWord + 1 > sizeof(szArg))
|
---|
| 2196 | return parseError(pStrm, 1, "Too long parameter declaration");
|
---|
| 2197 |
|
---|
| 2198 | szArg[cchArg++] = ' ';
|
---|
| 2199 | memcpy(&szArg[cchArg], pszWord, cchWord);
|
---|
| 2200 | cchArg += cchWord;
|
---|
| 2201 | szArg[cchArg] = '\0';
|
---|
[40557] | 2202 | cchName = cchWord;
|
---|
| 2203 | }
|
---|
[40556] | 2204 | break;
|
---|
| 2205 | }
|
---|
| 2206 |
|
---|
| 2207 | case '*':
|
---|
[40557] | 2208 | {
|
---|
| 2209 | if (!pArg)
|
---|
| 2210 | return parseError(pStrm, 1, "A parameter type does not start with an asterix");
|
---|
[40569] | 2211 | if (cchArg + sizeof(" *") >= sizeof(szArg))
|
---|
| 2212 | return parseError(pStrm, 1, "Too long parameter declaration");
|
---|
| 2213 | szArg[cchArg++] = ' ';
|
---|
| 2214 | szArg[cchArg++] = '*';
|
---|
| 2215 | szArg[cchArg ] = '\0';
|
---|
[40557] | 2216 | cchName = 0;
|
---|
| 2217 | break;
|
---|
| 2218 | }
|
---|
[40556] | 2219 |
|
---|
| 2220 | case ~(unsigned)0:
|
---|
[40557] | 2221 | return parseError(pStrm, 0, "Missing closing ')' on probe");
|
---|
[40556] | 2222 | }
|
---|
| 2223 | }
|
---|
| 2224 | }
|
---|
| 2225 |
|
---|
| 2226 | /**
|
---|
| 2227 | * Parses a D provider statement.
|
---|
| 2228 | *
|
---|
| 2229 | * @returns Suitable exit code, errors message already written on failure.
|
---|
| 2230 | * @param pStrm The stream.
|
---|
| 2231 | */
|
---|
[40554] | 2232 | static RTEXITCODE parseProvider(PSCMSTREAM pStrm)
|
---|
| 2233 | {
|
---|
[40549] | 2234 | /*
|
---|
[40556] | 2235 | * Next up is a name followed by a curly bracket. Ignore comments.
|
---|
[40549] | 2236 | */
|
---|
[40554] | 2237 | RTEXITCODE rcExit = parseSkipSpacesAndComments(pStrm);
|
---|
| 2238 | if (rcExit != RTEXITCODE_SUCCESS)
|
---|
| 2239 | return parseError(pStrm, 1, "Expected a provider name starting with an alphabetical character");
|
---|
| 2240 | size_t cchName;
|
---|
| 2241 | const char *pszName = ScmStreamCGetWord(pStrm, &cchName);
|
---|
| 2242 | if (!pszName)
|
---|
| 2243 | return parseError(pStrm, 0, "Bad provider name");
|
---|
| 2244 | if (RT_C_IS_DIGIT(pszName[cchName - 1]))
|
---|
| 2245 | return parseError(pStrm, 1, "A provider name cannot end with digit");
|
---|
| 2246 |
|
---|
[40555] | 2247 | unsigned ch = parseGetNextNonSpaceNonCommentCh(pStrm);
|
---|
[40554] | 2248 | if (ch != '{')
|
---|
| 2249 | return parseError(pStrm, 1, "Expected '{' after the provider name");
|
---|
| 2250 |
|
---|
| 2251 | /*
|
---|
| 2252 | * Create a provider instance.
|
---|
| 2253 | */
|
---|
| 2254 | PVTGPROVIDER pProv = (PVTGPROVIDER)RTMemAllocZ(sizeof(*pProv));
|
---|
| 2255 | if (!pProv)
|
---|
| 2256 | return parseError(pStrm, 0, "Out of memory");
|
---|
[40556] | 2257 | RTListInit(&pProv->ProbeHead);
|
---|
[40554] | 2258 | RTListAppend(&g_ProviderHead, &pProv->ListEntry);
|
---|
[40569] | 2259 | pProv->pszName = strtabInsertN(pszName, cchName);
|
---|
[40555] | 2260 | if (!pProv->pszName)
|
---|
[40554] | 2261 | return parseError(pStrm, 0, "Out of memory");
|
---|
| 2262 |
|
---|
| 2263 | /*
|
---|
[40555] | 2264 | * Parse loop.
|
---|
[40554] | 2265 | */
|
---|
[40555] | 2266 | for (;;)
|
---|
| 2267 | {
|
---|
| 2268 | ch = parseGetNextNonSpaceNonCommentCh(pStrm);
|
---|
| 2269 | switch (ch)
|
---|
| 2270 | {
|
---|
| 2271 | case 'p':
|
---|
| 2272 | if (ScmStreamCMatchingWordM1(pStrm, RT_STR_TUPLE("probe")))
|
---|
[40556] | 2273 | rcExit = parseProbe(pStrm, pProv);
|
---|
[40555] | 2274 | else
|
---|
[40556] | 2275 | rcExit = parseError(pStrm, 1, "Unexpected character");
|
---|
[40555] | 2276 | break;
|
---|
[40554] | 2277 |
|
---|
[40555] | 2278 | case '}':
|
---|
| 2279 | {
|
---|
| 2280 | size_t off = ScmStreamTell(pStrm);
|
---|
| 2281 | ch = parseGetNextNonSpaceNonCommentCh(pStrm);
|
---|
[40556] | 2282 | if (ch == ';')
|
---|
| 2283 | return RTEXITCODE_SUCCESS;
|
---|
| 2284 | rcExit = parseErrorAbs(pStrm, off, "Expected ';'");
|
---|
| 2285 | break;
|
---|
[40555] | 2286 | }
|
---|
[40554] | 2287 |
|
---|
[40555] | 2288 | case ~(unsigned)0:
|
---|
[40556] | 2289 | rcExit = parseError(pStrm, 0, "Missing closing '}' on provider");
|
---|
| 2290 | break;
|
---|
[40555] | 2291 |
|
---|
| 2292 | default:
|
---|
[40556] | 2293 | rcExit = parseError(pStrm, 1, "Unexpected character");
|
---|
| 2294 | break;
|
---|
[40555] | 2295 | }
|
---|
[40556] | 2296 | if (rcExit != RTEXITCODE_SUCCESS)
|
---|
| 2297 | return rcExit;
|
---|
[40555] | 2298 | }
|
---|
[40554] | 2299 | }
|
---|
| 2300 |
|
---|
| 2301 |
|
---|
| 2302 | static RTEXITCODE parseScript(const char *pszScript)
|
---|
| 2303 | {
|
---|
| 2304 | SCMSTREAM Strm;
|
---|
| 2305 | int rc = ScmStreamInitForReading(&Strm, pszScript);
|
---|
| 2306 | if (RT_FAILURE(rc))
|
---|
| 2307 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to open & read '%s' into memory: %Rrc", pszScript, rc);
|
---|
| 2308 | if (g_cVerbosity > 0)
|
---|
| 2309 | RTMsgInfo("Parsing '%s'...", pszScript);
|
---|
| 2310 |
|
---|
| 2311 | RTEXITCODE rcExit = RTEXITCODE_SUCCESS;
|
---|
| 2312 | unsigned ch;
|
---|
| 2313 | while ((ch = ScmStreamGetCh(&Strm)) != ~(unsigned)0)
|
---|
| 2314 | {
|
---|
| 2315 | if (RT_C_IS_SPACE(ch))
|
---|
| 2316 | continue;
|
---|
| 2317 | switch (ch)
|
---|
| 2318 | {
|
---|
| 2319 | case '/':
|
---|
| 2320 | ch = ScmStreamGetCh(&Strm);
|
---|
| 2321 | if (ch == '*')
|
---|
| 2322 | rcExit = parseMultiLineComment(&Strm);
|
---|
| 2323 | else if (ch == '/')
|
---|
| 2324 | rcExit = parseOneLineComment(&Strm);
|
---|
| 2325 | else
|
---|
| 2326 | rcExit = parseError(&Strm, 2, "Unexpected character");
|
---|
| 2327 | break;
|
---|
| 2328 |
|
---|
| 2329 | case 'p':
|
---|
| 2330 | if (ScmStreamCMatchingWordM1(&Strm, RT_STR_TUPLE("provider")))
|
---|
| 2331 | rcExit = parseProvider(&Strm);
|
---|
| 2332 | else
|
---|
| 2333 | rcExit = parseError(&Strm, 1, "Unexpected character");
|
---|
| 2334 | break;
|
---|
| 2335 |
|
---|
| 2336 | case '#':
|
---|
[40557] | 2337 | {
|
---|
| 2338 | ch = parseGetNextNonSpaceNonCommentChOnPpLine(&Strm);
|
---|
| 2339 | if (ch == ~(unsigned)0)
|
---|
[40826] | 2340 | rcExit = RTEXITCODE_FAILURE;
|
---|
[40557] | 2341 | else if (ch == 'p' && ScmStreamCMatchingWordM1(&Strm, RT_STR_TUPLE("pragma")))
|
---|
| 2342 | rcExit = parsePragma(&Strm);
|
---|
| 2343 | else
|
---|
| 2344 | rcExit = parseError(&Strm, 1, "Unsupported preprocessor directive");
|
---|
[40554] | 2345 | break;
|
---|
[40557] | 2346 | }
|
---|
[40554] | 2347 |
|
---|
| 2348 | default:
|
---|
| 2349 | rcExit = parseError(&Strm, 1, "Unexpected character");
|
---|
| 2350 | break;
|
---|
| 2351 | }
|
---|
| 2352 | if (rcExit != RTEXITCODE_SUCCESS)
|
---|
| 2353 | return rcExit;
|
---|
| 2354 | }
|
---|
| 2355 |
|
---|
| 2356 | ScmStreamDelete(&Strm);
|
---|
| 2357 | if (g_cVerbosity > 0 && rcExit == RTEXITCODE_SUCCESS)
|
---|
| 2358 | RTMsgInfo("Successfully parsed '%s'.", pszScript);
|
---|
| 2359 | return rcExit;
|
---|
| 2360 | }
|
---|
| 2361 |
|
---|
| 2362 |
|
---|
| 2363 | /**
|
---|
| 2364 | * Parses the arguments.
|
---|
| 2365 | */
|
---|
| 2366 | static RTEXITCODE parseArguments(int argc, char **argv)
|
---|
| 2367 | {
|
---|
[40570] | 2368 | /*
|
---|
| 2369 | * Set / Adjust defaults.
|
---|
| 2370 | */
|
---|
| 2371 | int rc = RTPathAbs(g_pszAssemblerIncVal, g_szAssemblerIncVal, sizeof(g_szAssemblerIncVal) - 1);
|
---|
| 2372 | if (RT_FAILURE(rc))
|
---|
| 2373 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTPathAbs failed: %Rrc", rc);
|
---|
[103275] | 2374 | strcat(g_szAssemblerIncVal, "/");
|
---|
[40570] | 2375 | g_pszAssemblerIncVal = g_szAssemblerIncVal;
|
---|
| 2376 |
|
---|
| 2377 | /*
|
---|
| 2378 | * Option config.
|
---|
| 2379 | */
|
---|
[40554] | 2380 | enum
|
---|
| 2381 | {
|
---|
| 2382 | kVBoxTpGOpt_32Bit = 1000,
|
---|
| 2383 | kVBoxTpGOpt_64Bit,
|
---|
[41342] | 2384 | kVBoxTpGOpt_GenerateWrapperHeader,
|
---|
[40554] | 2385 | kVBoxTpGOpt_Assembler,
|
---|
| 2386 | kVBoxTpGOpt_AssemblerFmtOpt,
|
---|
| 2387 | kVBoxTpGOpt_AssemblerFmtVal,
|
---|
| 2388 | kVBoxTpGOpt_AssemblerOutputOpt,
|
---|
| 2389 | kVBoxTpGOpt_AssemblerOption,
|
---|
[40975] | 2390 | kVBoxTpGOpt_Pic,
|
---|
[40597] | 2391 | kVBoxTpGOpt_ProbeFnName,
|
---|
| 2392 | kVBoxTpGOpt_ProbeFnImported,
|
---|
[40975] | 2393 | kVBoxTpGOpt_ProbeFnNotImported,
|
---|
[41338] | 2394 | kVBoxTpGOpt_Host32Bit,
|
---|
| 2395 | kVBoxTpGOpt_Host64Bit,
|
---|
| 2396 | kVBoxTpGOpt_RawModeContext,
|
---|
| 2397 | kVBoxTpGOpt_Ring0Context,
|
---|
[43055] | 2398 | kVBoxTpGOpt_Ring0ContextAgnostic,
|
---|
[41338] | 2399 | kVBoxTpGOpt_Ring3Context,
|
---|
[40554] | 2400 | kVBoxTpGOpt_End
|
---|
| 2401 | };
|
---|
| 2402 |
|
---|
[40549] | 2403 | static RTGETOPTDEF const s_aOpts[] =
|
---|
| 2404 | {
|
---|
[40554] | 2405 | /* dtrace w/ long options */
|
---|
| 2406 | { "-32", kVBoxTpGOpt_32Bit, RTGETOPT_REQ_NOTHING },
|
---|
| 2407 | { "-64", kVBoxTpGOpt_64Bit, RTGETOPT_REQ_NOTHING },
|
---|
[40549] | 2408 | { "--apply-cpp", 'C', RTGETOPT_REQ_NOTHING },
|
---|
| 2409 | { "--generate-obj", 'G', RTGETOPT_REQ_NOTHING },
|
---|
| 2410 | { "--generate-header", 'h', RTGETOPT_REQ_NOTHING },
|
---|
| 2411 | { "--output", 'o', RTGETOPT_REQ_STRING },
|
---|
| 2412 | { "--script", 's', RTGETOPT_REQ_STRING },
|
---|
[40554] | 2413 | { "--verbose", 'v', RTGETOPT_REQ_NOTHING },
|
---|
[41176] | 2414 | /* our stuff */
|
---|
[41342] | 2415 | { "--generate-wrapper-header", kVBoxTpGOpt_GenerateWrapperHeader, RTGETOPT_REQ_NOTHING },
|
---|
[40549] | 2416 | { "--assembler", kVBoxTpGOpt_Assembler, RTGETOPT_REQ_STRING },
|
---|
| 2417 | { "--assembler-fmt-opt", kVBoxTpGOpt_AssemblerFmtOpt, RTGETOPT_REQ_STRING },
|
---|
| 2418 | { "--assembler-fmt-val", kVBoxTpGOpt_AssemblerFmtVal, RTGETOPT_REQ_STRING },
|
---|
| 2419 | { "--assembler-output-opt", kVBoxTpGOpt_AssemblerOutputOpt, RTGETOPT_REQ_STRING },
|
---|
| 2420 | { "--assembler-option", kVBoxTpGOpt_AssemblerOption, RTGETOPT_REQ_STRING },
|
---|
[40975] | 2421 | { "--pic", kVBoxTpGOpt_Pic, RTGETOPT_REQ_NOTHING },
|
---|
[40597] | 2422 | { "--probe-fn-name", kVBoxTpGOpt_ProbeFnName, RTGETOPT_REQ_STRING },
|
---|
[40975] | 2423 | { "--probe-fn-imported", kVBoxTpGOpt_ProbeFnImported, RTGETOPT_REQ_NOTHING },
|
---|
| 2424 | { "--probe-fn-not-imported", kVBoxTpGOpt_ProbeFnNotImported, RTGETOPT_REQ_NOTHING },
|
---|
[41338] | 2425 | { "--host-32-bit", kVBoxTpGOpt_Host32Bit, RTGETOPT_REQ_NOTHING },
|
---|
| 2426 | { "--host-64-bit", kVBoxTpGOpt_Host64Bit, RTGETOPT_REQ_NOTHING },
|
---|
| 2427 | { "--raw-mode-context", kVBoxTpGOpt_RawModeContext, RTGETOPT_REQ_NOTHING },
|
---|
| 2428 | { "--ring-0-context", kVBoxTpGOpt_Ring0Context, RTGETOPT_REQ_NOTHING },
|
---|
[43055] | 2429 | { "--ring-0-context-agnostic", kVBoxTpGOpt_Ring0ContextAgnostic, RTGETOPT_REQ_NOTHING },
|
---|
[41338] | 2430 | { "--ring-3-context", kVBoxTpGOpt_Ring3Context, RTGETOPT_REQ_NOTHING },
|
---|
[40857] | 2431 | /** @todo We're missing a bunch of assembler options! */
|
---|
[40549] | 2432 | };
|
---|
| 2433 |
|
---|
| 2434 | RTGETOPTUNION ValueUnion;
|
---|
| 2435 | RTGETOPTSTATE GetOptState;
|
---|
[40570] | 2436 | rc = RTGetOptInit(&GetOptState, argc, argv, &s_aOpts[0], RT_ELEMENTS(s_aOpts), 1, RTGETOPTINIT_FLAGS_OPTS_FIRST);
|
---|
[40554] | 2437 | AssertReleaseRCReturn(rc, RTEXITCODE_FAILURE);
|
---|
[40549] | 2438 |
|
---|
[40570] | 2439 | /*
|
---|
[41176] | 2440 | * Process the options.
|
---|
[40570] | 2441 | */
|
---|
[40549] | 2442 | while ((rc = RTGetOpt(&GetOptState, &ValueUnion)) != 0)
|
---|
| 2443 | {
|
---|
| 2444 | switch (rc)
|
---|
| 2445 | {
|
---|
[40554] | 2446 | /*
|
---|
| 2447 | * DTrace compatible options.
|
---|
| 2448 | */
|
---|
| 2449 | case kVBoxTpGOpt_32Bit:
|
---|
[41338] | 2450 | g_cHostBits = g_cBits = 32;
|
---|
[40570] | 2451 | g_pszAssemblerFmtVal = g_szAssemblerFmtVal32;
|
---|
[40554] | 2452 | break;
|
---|
| 2453 |
|
---|
| 2454 | case kVBoxTpGOpt_64Bit:
|
---|
[41338] | 2455 | g_cHostBits = g_cBits = 64;
|
---|
[40570] | 2456 | g_pszAssemblerFmtVal = g_szAssemblerFmtVal64;
|
---|
[40554] | 2457 | break;
|
---|
| 2458 |
|
---|
| 2459 | case 'C':
|
---|
| 2460 | g_fApplyCpp = true;
|
---|
| 2461 | RTMsgWarning("Ignoring the -C option - no preprocessing of the D script will be performed");
|
---|
| 2462 | break;
|
---|
| 2463 |
|
---|
| 2464 | case 'G':
|
---|
| 2465 | if ( g_enmAction != kVBoxTpGAction_Nothing
|
---|
| 2466 | && g_enmAction != kVBoxTpGAction_GenerateObject)
|
---|
[41342] | 2467 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, "-G does not mix with -h or --generate-wrapper-header");
|
---|
[40554] | 2468 | g_enmAction = kVBoxTpGAction_GenerateObject;
|
---|
| 2469 | break;
|
---|
| 2470 |
|
---|
[40549] | 2471 | case 'h':
|
---|
[40554] | 2472 | if (!strcmp(GetOptState.pDef->pszLong, "--generate-header"))
|
---|
| 2473 | {
|
---|
| 2474 | if ( g_enmAction != kVBoxTpGAction_Nothing
|
---|
| 2475 | && g_enmAction != kVBoxTpGAction_GenerateHeader)
|
---|
[41342] | 2476 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, "-h does not mix with -G or --generate-wrapper-header");
|
---|
[40554] | 2477 | g_enmAction = kVBoxTpGAction_GenerateHeader;
|
---|
| 2478 | }
|
---|
| 2479 | else
|
---|
| 2480 | {
|
---|
| 2481 | /* --help or similar */
|
---|
| 2482 | RTPrintf("VirtualBox Tracepoint Generator\n"
|
---|
| 2483 | "\n"
|
---|
| 2484 | "Usage: %s [options]\n"
|
---|
| 2485 | "\n"
|
---|
| 2486 | "Options:\n", RTProcShortName());
|
---|
| 2487 | for (size_t i = 0; i < RT_ELEMENTS(s_aOpts); i++)
|
---|
| 2488 | if ((unsigned)s_aOpts[i].iShort < 128)
|
---|
| 2489 | RTPrintf(" -%c,%s\n", s_aOpts[i].iShort, s_aOpts[i].pszLong);
|
---|
| 2490 | else
|
---|
| 2491 | RTPrintf(" %s\n", s_aOpts[i].pszLong);
|
---|
| 2492 | return RTEXITCODE_SUCCESS;
|
---|
| 2493 | }
|
---|
| 2494 | break;
|
---|
[40549] | 2495 |
|
---|
[40554] | 2496 | case 'o':
|
---|
| 2497 | if (g_pszOutput)
|
---|
| 2498 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Output file is already set to '%s'", g_pszOutput);
|
---|
| 2499 | g_pszOutput = ValueUnion.psz;
|
---|
| 2500 | break;
|
---|
| 2501 |
|
---|
| 2502 | case 's':
|
---|
| 2503 | if (g_pszScript)
|
---|
| 2504 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Script file is already set to '%s'", g_pszScript);
|
---|
| 2505 | g_pszScript = ValueUnion.psz;
|
---|
| 2506 | break;
|
---|
| 2507 |
|
---|
| 2508 | case 'v':
|
---|
| 2509 | g_cVerbosity++;
|
---|
| 2510 | break;
|
---|
| 2511 |
|
---|
[40549] | 2512 | case 'V':
|
---|
| 2513 | {
|
---|
| 2514 | /* The following is assuming that svn does it's job here. */
|
---|
| 2515 | static const char s_szRev[] = "$Revision: 104620 $";
|
---|
| 2516 | const char *psz = RTStrStripL(strchr(s_szRev, ' '));
|
---|
| 2517 | RTPrintf("r%.*s\n", strchr(psz, ' ') - psz, psz);
|
---|
[40554] | 2518 | return RTEXITCODE_SUCCESS;
|
---|
[40549] | 2519 | }
|
---|
| 2520 |
|
---|
| 2521 | case VINF_GETOPT_NOT_OPTION:
|
---|
[40554] | 2522 | if (g_enmAction == kVBoxTpGAction_GenerateObject)
|
---|
[40549] | 2523 | break; /* object files, ignore them. */
|
---|
[40554] | 2524 | return RTGetOptPrintError(rc, &ValueUnion);
|
---|
[40549] | 2525 |
|
---|
[40554] | 2526 |
|
---|
| 2527 | /*
|
---|
[40597] | 2528 | * Our options.
|
---|
[40554] | 2529 | */
|
---|
[41342] | 2530 | case kVBoxTpGOpt_GenerateWrapperHeader:
|
---|
| 2531 | if ( g_enmAction != kVBoxTpGAction_Nothing
|
---|
| 2532 | && g_enmAction != kVBoxTpGAction_GenerateWrapperHeader)
|
---|
| 2533 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, "--generate-wrapper-header does not mix with -h or -G");
|
---|
| 2534 | g_enmAction = kVBoxTpGAction_GenerateWrapperHeader;
|
---|
| 2535 | break;
|
---|
| 2536 |
|
---|
[40554] | 2537 | case kVBoxTpGOpt_Assembler:
|
---|
| 2538 | g_pszAssembler = ValueUnion.psz;
|
---|
| 2539 | break;
|
---|
| 2540 |
|
---|
| 2541 | case kVBoxTpGOpt_AssemblerFmtOpt:
|
---|
| 2542 | g_pszAssemblerFmtOpt = ValueUnion.psz;
|
---|
| 2543 | break;
|
---|
| 2544 |
|
---|
| 2545 | case kVBoxTpGOpt_AssemblerFmtVal:
|
---|
| 2546 | g_pszAssemblerFmtVal = ValueUnion.psz;
|
---|
| 2547 | break;
|
---|
| 2548 |
|
---|
| 2549 | case kVBoxTpGOpt_AssemblerOutputOpt:
|
---|
| 2550 | g_pszAssemblerOutputOpt = ValueUnion.psz;
|
---|
| 2551 | break;
|
---|
| 2552 |
|
---|
| 2553 | case kVBoxTpGOpt_AssemblerOption:
|
---|
| 2554 | if (g_cAssemblerOptions >= RT_ELEMENTS(g_apszAssemblerOptions))
|
---|
| 2555 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Too many assembly options (max %u)", RT_ELEMENTS(g_apszAssemblerOptions));
|
---|
| 2556 | g_apszAssemblerOptions[g_cAssemblerOptions] = ValueUnion.psz;
|
---|
| 2557 | g_cAssemblerOptions++;
|
---|
| 2558 | break;
|
---|
[40604] | 2559 |
|
---|
[40975] | 2560 | case kVBoxTpGOpt_Pic:
|
---|
| 2561 | g_fPic = true;
|
---|
| 2562 | break;
|
---|
| 2563 |
|
---|
[40597] | 2564 | case kVBoxTpGOpt_ProbeFnName:
|
---|
| 2565 | g_pszProbeFnName = ValueUnion.psz;
|
---|
| 2566 | break;
|
---|
[40554] | 2567 |
|
---|
[40597] | 2568 | case kVBoxTpGOpt_ProbeFnImported:
|
---|
[40975] | 2569 | g_fProbeFnImported = true;
|
---|
[40597] | 2570 | break;
|
---|
| 2571 |
|
---|
[40975] | 2572 | case kVBoxTpGOpt_ProbeFnNotImported:
|
---|
| 2573 | g_fProbeFnImported = false;
|
---|
| 2574 | break;
|
---|
| 2575 |
|
---|
[41338] | 2576 | case kVBoxTpGOpt_Host32Bit:
|
---|
| 2577 | g_cHostBits = 32;
|
---|
| 2578 | break;
|
---|
| 2579 |
|
---|
| 2580 | case kVBoxTpGOpt_Host64Bit:
|
---|
| 2581 | g_cHostBits = 64;
|
---|
| 2582 | break;
|
---|
| 2583 |
|
---|
| 2584 | case kVBoxTpGOpt_RawModeContext:
|
---|
| 2585 | g_fTypeContext = VTG_TYPE_CTX_RC;
|
---|
[41342] | 2586 | g_pszContextDefine = "IN_RC";
|
---|
[43055] | 2587 | g_pszContextDefine2 = NULL;
|
---|
[41338] | 2588 | break;
|
---|
| 2589 |
|
---|
| 2590 | case kVBoxTpGOpt_Ring0Context:
|
---|
| 2591 | g_fTypeContext = VTG_TYPE_CTX_R0;
|
---|
[41342] | 2592 | g_pszContextDefine = "IN_RING0";
|
---|
[43055] | 2593 | g_pszContextDefine2 = NULL;
|
---|
[41338] | 2594 | break;
|
---|
| 2595 |
|
---|
[43055] | 2596 | case kVBoxTpGOpt_Ring0ContextAgnostic:
|
---|
| 2597 | g_fTypeContext = VTG_TYPE_CTX_R0;
|
---|
| 2598 | g_pszContextDefine = "IN_RING0_AGNOSTIC";
|
---|
| 2599 | g_pszContextDefine2 = "IN_RING0";
|
---|
| 2600 | break;
|
---|
| 2601 |
|
---|
[41338] | 2602 | case kVBoxTpGOpt_Ring3Context:
|
---|
| 2603 | g_fTypeContext = VTG_TYPE_CTX_R3;
|
---|
[41342] | 2604 | g_pszContextDefine = "IN_RING3";
|
---|
[43055] | 2605 | g_pszContextDefine2 = NULL;
|
---|
[41338] | 2606 | break;
|
---|
| 2607 |
|
---|
| 2608 |
|
---|
[40554] | 2609 | /*
|
---|
| 2610 | * Errors and bugs.
|
---|
| 2611 | */
|
---|
[40549] | 2612 | default:
|
---|
[40554] | 2613 | return RTGetOptPrintError(rc, &ValueUnion);
|
---|
| 2614 | }
|
---|
| 2615 | }
|
---|
| 2616 |
|
---|
| 2617 | /*
|
---|
| 2618 | * Check that we've got all we need.
|
---|
| 2619 | */
|
---|
| 2620 | if (g_enmAction == kVBoxTpGAction_Nothing)
|
---|
[41342] | 2621 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, "No action specified (-h, -G or --generate-wrapper-header)");
|
---|
[40554] | 2622 | if (!g_pszScript)
|
---|
| 2623 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, "No script file specified (-s)");
|
---|
| 2624 | if (!g_pszOutput)
|
---|
| 2625 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, "No output file specified (-o)");
|
---|
| 2626 |
|
---|
| 2627 | return RTEXITCODE_SUCCESS;
|
---|
| 2628 | }
|
---|
| 2629 |
|
---|
| 2630 |
|
---|
| 2631 | int main(int argc, char **argv)
|
---|
| 2632 | {
|
---|
| 2633 | int rc = RTR3InitExe(argc, &argv, 0);
|
---|
| 2634 | if (RT_FAILURE(rc))
|
---|
| 2635 | return 1;
|
---|
| 2636 |
|
---|
| 2637 | RTEXITCODE rcExit = parseArguments(argc, argv);
|
---|
| 2638 | if (rcExit == RTEXITCODE_SUCCESS)
|
---|
| 2639 | {
|
---|
| 2640 | /*
|
---|
| 2641 | * Parse the script.
|
---|
| 2642 | */
|
---|
[40569] | 2643 | RTListInit(&g_ProviderHead);
|
---|
| 2644 | rcExit = parseScript(g_pszScript);
|
---|
| 2645 | if (rcExit == RTEXITCODE_SUCCESS)
|
---|
[40554] | 2646 | {
|
---|
[40569] | 2647 | /*
|
---|
| 2648 | * Take action.
|
---|
| 2649 | */
|
---|
| 2650 | if (g_enmAction == kVBoxTpGAction_GenerateHeader)
|
---|
[41342] | 2651 | rcExit = generateFile(g_pszOutput, "header", generateHeader);
|
---|
| 2652 | else if (g_enmAction == kVBoxTpGAction_GenerateWrapperHeader)
|
---|
| 2653 | rcExit = generateFile(g_pszOutput, "wrapper header", generateWrapperHeader);
|
---|
[40569] | 2654 | else
|
---|
| 2655 | rcExit = generateObject(g_pszOutput, g_pszTempAsm);
|
---|
[40549] | 2656 | }
|
---|
| 2657 | }
|
---|
| 2658 |
|
---|
[40878] | 2659 | if (rcExit == RTEXITCODE_SUCCESS && g_cTypeErrors > 0)
|
---|
| 2660 | rcExit = RTEXITCODE_FAILURE;
|
---|
[40554] | 2661 | return rcExit;
|
---|
| 2662 | }
|
---|
[40549] | 2663 |
|
---|