VirtualBox

source: vbox/trunk/src/VBox/Runtime/VBox/log-vbox.cpp

Last change on this file was 101035, checked in by vboxsync, 7 months ago

Initial commit (based draft v2 / on patch v5) for implementing platform architecture support for x86 and ARM. bugref:10384

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 25.1 KB
Line 
1/* $Id: log-vbox.cpp 101035 2023-09-07 08:59:15Z vboxsync $ */
2/** @file
3 * VirtualBox Runtime - Logging configuration.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
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 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37/** @page pg_rtlog Runtime - Logging
38 *
39 * VBox uses the IPRT logging system which supports group level flags and multiple
40 * destinations. The GC logging is making it even more interesting since GC logging will
41 * have to be buffered and written when back in host context.
42 *
43 * [more later]
44 *
45 *
46 * @section sec_logging_destination The Destination Specifier.
47 *
48 * The {logger-env-base}_DEST environment variable can be used to specify where
49 * the log output goes. The following specifiers are recognized:
50 *
51 * - file=\<filename\>
52 * This sets the logger output filename to \<filename\>. Not formatting
53 * or anything is supported. Each logger specifies a default name if
54 * file logging should be enabled by default.
55 *
56 * - nofile
57 * This disables the file output.
58 *
59 * - stdout
60 * Enables logger output to stdout.
61 *
62 * - nostdout
63 * Disables logger output to stdout.
64 *
65 * - stderr
66 * Enables logger output to stderr.
67 *
68 * - nostderr
69 * Disables logger output to stderr.
70 *
71 * - debugger
72 * Enables logger output to native debugger. (Win32/64 only)
73 *
74 * - nodebugger
75 * Disables logger output to native debugger. (Win32/64 only)
76 *
77 * - user
78 * Enables logger output to special backdoor if in guest r0.
79 *
80 * - nodebugger
81 * Disables logger output to special user stream.
82 *
83 *
84 *
85 * @section sec_logging_group The Group Specifier.
86 *
87 * The {logger-env-base} environment variable can be used to specify which
88 * logger groups to enable and which to disable. By default all groups are
89 * disabled. For your convenience this specifier is case in-sensitive (ASCII).
90 *
91 * The specifier is evaluated from left to right.
92 *
93 * [more later]
94 *
95 * The groups settings can be reprogrammed during execution using the
96 * RTLogGroupSettings() command and a group specifier.
97 *
98 *
99 *
100 * @section sec_logging_default The Default Logger
101 *
102 * The default logger uses VBOX_LOG_DEST as destination specifier. File output is
103 * enabled by default and goes to a file "./VBox-\<pid\>.log".
104 *
105 * The default logger have all groups turned off by default to force the developer
106 * to be careful with what log information to collect - logging everything is
107 * generally NOT a good idea.
108 *
109 * The log groups of the default logger can be found in the LOGGROUP in enum. The
110 * VBOX_LOG environment variable and the .log debugger command can be used to
111 * configure the groups.
112 *
113 * Each group have flags in addition to the enable/disable flag. These flags can
114 * be appended to the group name using dot separators. The flags correspond to
115 * RTLOGGRPFLAGS and have a short and a long version:
116 *
117 * - e - Enabled: Whether the group is enabled at all.
118 * - l - Level2: Level-2 logging.
119 * - f - Flow: Execution flow logging (entry messages)
120 * - s - Sander: Special Sander logging messages.
121 * - b - Bird: Special Bird logging messages.
122 *
123 * @todo Update this section...
124 *
125 * Example:
126 *
127 * VBOX_LOG=+all+pgm.e.s.b.z.l-qemu
128 *
129 * Space and ';' separators are allowed:
130 *
131 * VBOX_LOG=+all +pgm.e.s.b.z.l ; - qemu
132 *
133 */
134
135
136/*********************************************************************************************************************************
137* Header Files *
138*********************************************************************************************************************************/
139#ifdef IN_RING3
140# if defined(RT_OS_WINDOWS)
141# include <iprt/win/windows.h>
142# elif defined(RT_OS_LINUX)
143# include <stdio.h>
144# include <unistd.h>
145# elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
146# include <sys/param.h>
147# include <sys/sysctl.h>
148# if defined(RT_OS_FREEBSD)
149# include <sys/user.h>
150# endif
151# include <stdlib.h>
152# include <unistd.h>
153# elif defined(RT_OS_HAIKU)
154# include <OS.h>
155# elif defined(RT_OS_SOLARIS)
156# define _STRUCTURED_PROC 1
157# undef _FILE_OFFSET_BITS /* procfs doesn't like this */
158# include <stdio.h>
159# include <sys/procfs.h>
160# include <unistd.h>
161# elif defined(RT_OS_OS2)
162# include <stdlib.h>
163# endif
164#endif
165
166#include <VBox/log.h>
167#include <iprt/asm.h>
168#include <iprt/errcore.h>
169#include <iprt/time.h>
170#ifdef IN_RING3
171# include <iprt/param.h>
172# include <iprt/assert.h>
173# include <iprt/path.h>
174# include <iprt/process.h>
175# include <iprt/string.h>
176# include <iprt/mem.h>
177# ifdef IPRT_NO_CRT
178# include <iprt/stream.h>
179# else
180# include <stdio.h>
181# endif
182#endif
183#if defined(IN_RING0) && defined(RT_OS_DARWIN)
184# include <iprt/asm-amd64-x86.h>
185# include <iprt/thread.h>
186#endif
187
188
189/*********************************************************************************************************************************
190* Global Variables *
191*********************************************************************************************************************************/
192/** The default logger. */
193static PRTLOGGER g_pLogger = NULL;
194/** The default logger groups.
195 * This must match LOGGROUP! */
196static const char *g_apszGroups[] =
197VBOX_LOGGROUP_NAMES;
198
199
200/**
201 * Creates the default logger instance for a VBox process.
202 *
203 * @returns Pointer to the logger instance.
204 */
205RTDECL(PRTLOGGER) RTLogDefaultInit(void)
206{
207 /*
208 * Initialize the default logger instance.
209 * Take care to do this once and not recursively.
210 */
211 static volatile uint32_t fInitializing = 0;
212 PRTLOGGER pLogger;
213 int rc;
214
215 if (g_pLogger || !ASMAtomicCmpXchgU32(&fInitializing, 1, 0))
216 return g_pLogger;
217
218#ifdef IN_RING3
219 /*
220 * Assert the group definitions.
221 */
222#define ASSERT_LOG_GROUP(grp) ASSERT_LOG_GROUP2(LOG_GROUP_##grp, #grp)
223#ifdef IPRT_NO_CRT
224# define ASSERT_LOG_GROUP2(def, str) \
225 do { if (strcmp(g_apszGroups[def], str)) { RTPrintf("%s='%s' expects '%s'\n", #def, g_apszGroups[def], str); RTAssertDoPanic(); } } while (0)
226# else
227# define ASSERT_LOG_GROUP2(def, str) \
228 do { if (strcmp(g_apszGroups[def], str)) { printf("%s='%s' expects '%s'\n", #def, g_apszGroups[def], str); RTAssertDoPanic(); } } while (0)
229# endif
230 ASSERT_LOG_GROUP(DEFAULT);
231 ASSERT_LOG_GROUP(AUDIO_MIXER);
232 ASSERT_LOG_GROUP(AUDIO_MIXER_BUFFER);
233 ASSERT_LOG_GROUP(AUTOLOGON);
234 ASSERT_LOG_GROUP(CFGM);
235 ASSERT_LOG_GROUP(CPUM);
236 ASSERT_LOG_GROUP(CSAM);
237 ASSERT_LOG_GROUP(DBGC);
238 ASSERT_LOG_GROUP(DBGF);
239 ASSERT_LOG_GROUP(DBGF_INFO);
240 ASSERT_LOG_GROUP(DBGG);
241 ASSERT_LOG_GROUP(DEV);
242 ASSERT_LOG_GROUP(DEV_AC97);
243 ASSERT_LOG_GROUP(DEV_ACPI);
244 ASSERT_LOG_GROUP(DEV_APIC);
245 ASSERT_LOG_GROUP(DEV_BUSLOGIC);
246 ASSERT_LOG_GROUP(DEV_DMA);
247 ASSERT_LOG_GROUP(DEV_E1000);
248 ASSERT_LOG_GROUP(DEV_EFI);
249 ASSERT_LOG_GROUP(DEV_EHCI);
250 ASSERT_LOG_GROUP(DEV_FDC);
251 ASSERT_LOG_GROUP(DEV_GIM);
252 ASSERT_LOG_GROUP(DEV_HDA);
253 ASSERT_LOG_GROUP(DEV_HDA_CODEC);
254 ASSERT_LOG_GROUP(DEV_HPET);
255 ASSERT_LOG_GROUP(DEV_IDE);
256 ASSERT_LOG_GROUP(DEV_INIP);
257 ASSERT_LOG_GROUP(DEV_KBD);
258 ASSERT_LOG_GROUP(DEV_LPC);
259 ASSERT_LOG_GROUP(DEV_LSILOGICSCSI);
260 ASSERT_LOG_GROUP(DEV_NVME);
261 ASSERT_LOG_GROUP(DEV_OHCI);
262 ASSERT_LOG_GROUP(DEV_PARALLEL);
263 ASSERT_LOG_GROUP(DEV_PC);
264 ASSERT_LOG_GROUP(DEV_PC_ARCH);
265 ASSERT_LOG_GROUP(DEV_PC_BIOS);
266 ASSERT_LOG_GROUP(DEV_PCI);
267 ASSERT_LOG_GROUP(DEV_PCI_RAW);
268 ASSERT_LOG_GROUP(DEV_PCNET);
269 ASSERT_LOG_GROUP(DEV_PIC);
270 ASSERT_LOG_GROUP(DEV_PIT);
271 ASSERT_LOG_GROUP(DEV_RTC);
272 ASSERT_LOG_GROUP(DEV_SB16);
273 ASSERT_LOG_GROUP(DEV_SERIAL);
274 ASSERT_LOG_GROUP(DEV_SMC);
275 ASSERT_LOG_GROUP(DEV_VGA);
276 ASSERT_LOG_GROUP(DEV_VIRTIO);
277 ASSERT_LOG_GROUP(DEV_VIRTIO_NET);
278 ASSERT_LOG_GROUP(DEV_VMM);
279 ASSERT_LOG_GROUP(DEV_VMM_BACKDOOR);
280 ASSERT_LOG_GROUP(DEV_VMM_STDERR);
281 ASSERT_LOG_GROUP(DEV_VMSVGA);
282 ASSERT_LOG_GROUP(DEV_XHCI);
283 ASSERT_LOG_GROUP(DIS);
284 ASSERT_LOG_GROUP(DRV);
285 ASSERT_LOG_GROUP(DRV_ACPI);
286 ASSERT_LOG_GROUP(DRV_AUDIO);
287 ASSERT_LOG_GROUP(DRV_BLOCK);
288 ASSERT_LOG_GROUP(DRV_CHAR);
289 ASSERT_LOG_GROUP(DRV_DISK_INTEGRITY);
290 ASSERT_LOG_GROUP(DRV_DISPLAY);
291 ASSERT_LOG_GROUP(DRV_FLOPPY);
292 ASSERT_LOG_GROUP(DRV_HOST_AUDIO);
293 ASSERT_LOG_GROUP(DRV_HOST_BASE);
294 ASSERT_LOG_GROUP(DRV_HOST_DVD);
295 ASSERT_LOG_GROUP(DRV_HOST_FLOPPY);
296 ASSERT_LOG_GROUP(DRV_HOST_PARALLEL);
297 ASSERT_LOG_GROUP(DRV_HOST_SERIAL);
298 ASSERT_LOG_GROUP(DRV_INTNET);
299 ASSERT_LOG_GROUP(DRV_ISO);
300 ASSERT_LOG_GROUP(DRV_KBD_QUEUE);
301 ASSERT_LOG_GROUP(DRV_LWIP);
302 ASSERT_LOG_GROUP(DRV_MINIPORT);
303 ASSERT_LOG_GROUP(DRV_MOUSE_QUEUE);
304 ASSERT_LOG_GROUP(DRV_NAMEDPIPE);
305 ASSERT_LOG_GROUP(DRV_NAT);
306 ASSERT_LOG_GROUP(DRV_RAW_IMAGE);
307 ASSERT_LOG_GROUP(DRV_SCSI);
308 ASSERT_LOG_GROUP(DRV_SCSIHOST);
309 ASSERT_LOG_GROUP(DRV_TCP);
310 ASSERT_LOG_GROUP(DRV_TRANSPORT_ASYNC);
311 ASSERT_LOG_GROUP(DRV_TUN);
312 ASSERT_LOG_GROUP(DRV_UDPTUNNEL);
313 ASSERT_LOG_GROUP(DRV_USBPROXY);
314 ASSERT_LOG_GROUP(DRV_VBOXHDD);
315 ASSERT_LOG_GROUP(DRV_VD);
316 ASSERT_LOG_GROUP(DRV_VRDE_AUDIO);
317 ASSERT_LOG_GROUP(DRV_VSWITCH);
318 ASSERT_LOG_GROUP(DRV_VUSB);
319 ASSERT_LOG_GROUP(EM);
320 ASSERT_LOG_GROUP(FTM);
321 ASSERT_LOG_GROUP(GIM);
322 ASSERT_LOG_GROUP(GMM);
323 ASSERT_LOG_GROUP(GUEST_CONTROL);
324 ASSERT_LOG_GROUP(GUEST_DND);
325 ASSERT_LOG_GROUP(GUI);
326 ASSERT_LOG_GROUP(GVMM);
327 ASSERT_LOG_GROUP(HGCM);
328 ASSERT_LOG_GROUP(HGSMI);
329 ASSERT_LOG_GROUP(HM);
330 ASSERT_LOG_GROUP(IEM);
331 ASSERT_LOG_GROUP(IEM_RE_NATIVE);
332 ASSERT_LOG_GROUP(IEM_RE_THREADED);
333 ASSERT_LOG_GROUP(IEM_SVM);
334 ASSERT_LOG_GROUP(IEM_VMX);
335 ASSERT_LOG_GROUP(IOM);
336 ASSERT_LOG_GROUP(IPC);
337 ASSERT_LOG_GROUP(LWIP);
338 ASSERT_LOG_GROUP(LWIP_API_LIB);
339 ASSERT_LOG_GROUP(LWIP_API_MSG);
340 ASSERT_LOG_GROUP(LWIP_ETHARP);
341 ASSERT_LOG_GROUP(LWIP_ICMP);
342 ASSERT_LOG_GROUP(LWIP_IGMP);
343 ASSERT_LOG_GROUP(LWIP_INET);
344 ASSERT_LOG_GROUP(LWIP_IP4);
345 ASSERT_LOG_GROUP(LWIP_IP4_REASS);
346 ASSERT_LOG_GROUP(LWIP_IP6);
347 ASSERT_LOG_GROUP(LWIP_MEM);
348 ASSERT_LOG_GROUP(LWIP_MEMP);
349 ASSERT_LOG_GROUP(LWIP_NETIF);
350 ASSERT_LOG_GROUP(LWIP_PBUF);
351 ASSERT_LOG_GROUP(LWIP_RAW);
352 ASSERT_LOG_GROUP(LWIP_SOCKETS);
353 ASSERT_LOG_GROUP(LWIP_SYS);
354 ASSERT_LOG_GROUP(LWIP_TCP);
355 ASSERT_LOG_GROUP(LWIP_TCPIP);
356 ASSERT_LOG_GROUP(LWIP_TCP_CWND);
357 ASSERT_LOG_GROUP(LWIP_TCP_FR);
358 ASSERT_LOG_GROUP(LWIP_TCP_INPUT);
359 ASSERT_LOG_GROUP(LWIP_TCP_OUTPUT);
360 ASSERT_LOG_GROUP(LWIP_TCP_QLEN);
361 ASSERT_LOG_GROUP(LWIP_TCP_RST);
362 ASSERT_LOG_GROUP(LWIP_TCP_RTO);
363 ASSERT_LOG_GROUP(LWIP_TCP_WND);
364 ASSERT_LOG_GROUP(LWIP_TIMERS);
365 ASSERT_LOG_GROUP(LWIP_UDP);
366 ASSERT_LOG_GROUP(MAIN);
367 ASSERT_LOG_GROUP(MAIN_ADDITIONSFACILITY);
368 ASSERT_LOG_GROUP(MAIN_APPLIANCE);
369 ASSERT_LOG_GROUP(MAIN_AUDIOADAPTER);
370 ASSERT_LOG_GROUP(MAIN_BANDWIDTHCONTROL);
371 ASSERT_LOG_GROUP(MAIN_BANDWIDTHGROUP);
372 ASSERT_LOG_GROUP(MAIN_CONSOLE);
373 ASSERT_LOG_GROUP(MAIN_DHCPSERVER);
374 ASSERT_LOG_GROUP(MAIN_DIRECTORY);
375 ASSERT_LOG_GROUP(MAIN_DISPLAY);
376 ASSERT_LOG_GROUP(MAIN_DISPLAYSOURCEBITMAP);
377 ASSERT_LOG_GROUP(MAIN_DNDBASE);
378 ASSERT_LOG_GROUP(MAIN_DNDSOURCE);
379 ASSERT_LOG_GROUP(MAIN_DNDTARGET);
380 ASSERT_LOG_GROUP(MAIN_EMULATEDUSB);
381 ASSERT_LOG_GROUP(MAIN_EVENT);
382 ASSERT_LOG_GROUP(MAIN_EVENTLISTENER);
383 ASSERT_LOG_GROUP(MAIN_EVENTSOURCE);
384 ASSERT_LOG_GROUP(MAIN_EXTPACK);
385 ASSERT_LOG_GROUP(MAIN_EXTPACKBASE);
386 ASSERT_LOG_GROUP(MAIN_EXTPACKFILE);
387 ASSERT_LOG_GROUP(MAIN_EXTPACKMANAGER);
388 ASSERT_LOG_GROUP(MAIN_EXTPACKPLUGIN);
389 ASSERT_LOG_GROUP(MAIN_FILE);
390 ASSERT_LOG_GROUP(MAIN_FIRMWARESETTINGS);
391 ASSERT_LOG_GROUP(MAIN_FRAMEBUFFER);
392 ASSERT_LOG_GROUP(MAIN_FRAMEBUFFEROVERLAY);
393 ASSERT_LOG_GROUP(MAIN_FSOBJINFO);
394 ASSERT_LOG_GROUP(MAIN_GUEST);
395 ASSERT_LOG_GROUP(MAIN_GUESTDIRECTORY);
396 ASSERT_LOG_GROUP(MAIN_GUESTDNDSOURCE);
397 ASSERT_LOG_GROUP(MAIN_GUESTDNDTARGET);
398 ASSERT_LOG_GROUP(MAIN_GUESTERRORINFO);
399 ASSERT_LOG_GROUP(MAIN_GUESTFILE);
400 ASSERT_LOG_GROUP(MAIN_GUESTFSOBJINFO);
401 ASSERT_LOG_GROUP(MAIN_GUESTOSTYPE);
402 ASSERT_LOG_GROUP(MAIN_GUESTPROCESS);
403 ASSERT_LOG_GROUP(MAIN_GUESTSESSION);
404 ASSERT_LOG_GROUP(MAIN_HOST);
405 ASSERT_LOG_GROUP(MAIN_HOSTNETWORKINTERFACE);
406 ASSERT_LOG_GROUP(MAIN_HOSTUSBDEVICE);
407 ASSERT_LOG_GROUP(MAIN_HOSTUSBDEVICEFILTER);
408 ASSERT_LOG_GROUP(MAIN_HOSTVIDEOINPUTDEVICE);
409 ASSERT_LOG_GROUP(MAIN_INTERNALMACHINECONTROL);
410 ASSERT_LOG_GROUP(MAIN_INTERNALSESSIONCONTROL);
411 ASSERT_LOG_GROUP(MAIN_KEYBOARD);
412 ASSERT_LOG_GROUP(MAIN_MACHINE);
413 ASSERT_LOG_GROUP(MAIN_MACHINEDEBUGGER);
414 ASSERT_LOG_GROUP(MAIN_MEDIUM);
415 ASSERT_LOG_GROUP(MAIN_MEDIUMATTACHMENT);
416 ASSERT_LOG_GROUP(MAIN_MEDIUMFORMAT);
417 ASSERT_LOG_GROUP(MAIN_MOUSE);
418 ASSERT_LOG_GROUP(MAIN_MOUSEPOINTERSHAPE);
419 ASSERT_LOG_GROUP(MAIN_NATENGINE);
420 ASSERT_LOG_GROUP(MAIN_NATNETWORK);
421 ASSERT_LOG_GROUP(MAIN_NETWORKADAPTER);
422 ASSERT_LOG_GROUP(MAIN_PARALLELPORT);
423 ASSERT_LOG_GROUP(MAIN_PCIADDRESS);
424 ASSERT_LOG_GROUP(MAIN_PCIDEVICEATTACHMENT);
425 ASSERT_LOG_GROUP(MAIN_PERFORMANCECOLLECTOR);
426 ASSERT_LOG_GROUP(MAIN_PERFORMANCEMETRIC);
427 ASSERT_LOG_GROUP(MAIN_PROCESS);
428 ASSERT_LOG_GROUP(MAIN_PROGRESS);
429 ASSERT_LOG_GROUP(MAIN_SERIALPORT);
430 ASSERT_LOG_GROUP(MAIN_SESSION);
431 ASSERT_LOG_GROUP(MAIN_SHAREDFOLDER);
432 ASSERT_LOG_GROUP(MAIN_SNAPSHOT);
433 ASSERT_LOG_GROUP(MAIN_STORAGECONTROLLER);
434 ASSERT_LOG_GROUP(MAIN_SYSTEMPROPERTIES);
435 ASSERT_LOG_GROUP(MAIN_TOKEN);
436 ASSERT_LOG_GROUP(MAIN_USBCONTROLLER);
437 ASSERT_LOG_GROUP(MAIN_USBDEVICE);
438 ASSERT_LOG_GROUP(MAIN_USBDEVICEFILTERS);
439 ASSERT_LOG_GROUP(MAIN_VIRTUALBOX);
440 ASSERT_LOG_GROUP(MAIN_VIRTUALBOXCLIENT);
441 ASSERT_LOG_GROUP(MAIN_VIRTUALBOXSDS);
442 ASSERT_LOG_GROUP(MAIN_VIRTUALSYSTEMDESCRIPTION);
443 ASSERT_LOG_GROUP(MAIN_VRDESERVER);
444 ASSERT_LOG_GROUP(MAIN_VRDESERVERINFO);
445 ASSERT_LOG_GROUP(MISC);
446 ASSERT_LOG_GROUP(MM);
447 ASSERT_LOG_GROUP(MM_HEAP);
448 ASSERT_LOG_GROUP(MM_HYPER);
449 ASSERT_LOG_GROUP(MM_HYPER_HEAP);
450 ASSERT_LOG_GROUP(MM_PHYS);
451 ASSERT_LOG_GROUP(MM_POOL);
452 ASSERT_LOG_GROUP(NAT_SERVICE);
453 ASSERT_LOG_GROUP(NET_ADP_DRV);
454 ASSERT_LOG_GROUP(NET_FLT_DRV);
455 ASSERT_LOG_GROUP(NET_SERVICE);
456 ASSERT_LOG_GROUP(NET_SHAPER);
457 ASSERT_LOG_GROUP(PATM);
458 ASSERT_LOG_GROUP(PDM);
459 ASSERT_LOG_GROUP(PDM_ASYNC_COMPLETION);
460 ASSERT_LOG_GROUP(PDM_BLK_CACHE);
461 ASSERT_LOG_GROUP(PDM_DEVICE);
462 ASSERT_LOG_GROUP(PDM_DRIVER);
463 ASSERT_LOG_GROUP(PDM_LDR);
464 ASSERT_LOG_GROUP(PDM_QUEUE);
465 ASSERT_LOG_GROUP(PGM);
466 ASSERT_LOG_GROUP(PGM_DYNMAP);
467 ASSERT_LOG_GROUP(PGM_PHYS);
468 ASSERT_LOG_GROUP(PGM_PHYS_ACCESS);
469 ASSERT_LOG_GROUP(PGM_POOL);
470 ASSERT_LOG_GROUP(PGM_SHARED);
471 ASSERT_LOG_GROUP(SELM);
472 ASSERT_LOG_GROUP(SHARED_CLIPBOARD);
473 ASSERT_LOG_GROUP(SHARED_CROPENGL);
474 ASSERT_LOG_GROUP(SHARED_FOLDERS);
475 ASSERT_LOG_GROUP(SHARED_OPENGL);
476 ASSERT_LOG_GROUP(SRV_INTNET);
477 ASSERT_LOG_GROUP(SSM);
478 ASSERT_LOG_GROUP(STAM);
479 ASSERT_LOG_GROUP(SUP);
480 ASSERT_LOG_GROUP(TM);
481 ASSERT_LOG_GROUP(TRPM);
482 ASSERT_LOG_GROUP(USB_CARDREADER);
483 ASSERT_LOG_GROUP(USB_DRV);
484 ASSERT_LOG_GROUP(USB_FILTER);
485 ASSERT_LOG_GROUP(USB_KBD);
486 ASSERT_LOG_GROUP(USB_MOUSE);
487 ASSERT_LOG_GROUP(USB_MSD);
488 ASSERT_LOG_GROUP(USB_REMOTE);
489 ASSERT_LOG_GROUP(USB_WEBCAM);
490 ASSERT_LOG_GROUP(VGDRV);
491 ASSERT_LOG_GROUP(VBGL);
492 ASSERT_LOG_GROUP(VD);
493 ASSERT_LOG_GROUP(VD_DMG);
494 ASSERT_LOG_GROUP(VD_ISCSI);
495 ASSERT_LOG_GROUP(VD_PARALLELS);
496 ASSERT_LOG_GROUP(VD_QCOW);
497 ASSERT_LOG_GROUP(VD_QED);
498 ASSERT_LOG_GROUP(VD_RAW);
499 ASSERT_LOG_GROUP(VD_VDI);
500 ASSERT_LOG_GROUP(VD_VHD);
501 ASSERT_LOG_GROUP(VD_VHDX);
502 ASSERT_LOG_GROUP(VD_VMDK);
503 ASSERT_LOG_GROUP(VM);
504 ASSERT_LOG_GROUP(VMM);
505 ASSERT_LOG_GROUP(VRDE);
506 ASSERT_LOG_GROUP(VRDP);
507 ASSERT_LOG_GROUP(VSCSI);
508 ASSERT_LOG_GROUP(WEBSERVICE);
509#undef ASSERT_LOG_GROUP
510#undef ASSERT_LOG_GROUP2
511#endif /* IN_RING3 */
512
513 /*
514 * Create the default logging instance.
515 */
516#ifdef IN_RING3
517 const char *pszExeName = RTProcShortName();
518 if (!pszExeName)
519 pszExeName = "VBox";
520 RTTIMESPEC TimeSpec;
521 RTTIME Time;
522 RTPROCESS pid = RTProcSelf();
523 RTTimeExplode(&Time, RTTimeNow(&TimeSpec));
524 rc = RTLogCreate(&pLogger, 0, NULL, "VBOX_LOG", RT_ELEMENTS(g_apszGroups), &g_apszGroups[0],
525# ifdef IN_GUEST
526 RTLOGDEST_USER /* backdoor */,
527 "./VBoxGAs-%04d-%02d-%02d-%02d-%02d-%02d.%03d-%s-%d.log",
528# else
529 RTLOGDEST_FILE,
530 "./%04d-%02d-%02d-%02d-%02d-%02d.%03d-%s-%d.log",
531# endif
532 Time.i32Year, Time.u8Month, Time.u8MonthDay, Time.u8Hour, Time.u8Minute, Time.u8Second,
533 Time.u32Nanosecond / 10000000, pszExeName, pid);
534 if (RT_SUCCESS(rc))
535 {
536 /*
537 * Write a log header.
538 */
539 char szBuf[80];
540 RTPROCESS pidParent = NIL_RTPROCESS;
541 RTProcQueryParent(pid, &pidParent);
542 RTLogLoggerEx(pLogger, 0, ~0U,
543 "Log created: %s\n"
544 "Process ID: %d (%#x)\n"
545 "Parent PID: %d (%#x)\n"
546 "Executable: %s\n",
547 RTTimeSpecToString(&TimeSpec, szBuf, sizeof(szBuf)),
548 pid, pid,
549 pidParent, pidParent,
550 RTProcExecutablePath());
551
552 /* executable and arguments - tricky and all platform specific. */
553# if defined(RT_OS_WINDOWS)
554 RTLogLoggerEx(pLogger, 0, ~0U, "Commandline: %ls\n", GetCommandLineW());
555
556# elif defined(RT_OS_SOLARIS)
557 psinfo_t psi;
558 RTStrPrintf(szBuf, sizeof(szBuf), "/proc/%ld/psinfo", (long)getpid());
559 FILE *pFile = fopen(szBuf, "rb");
560 if (pFile)
561 {
562 if (fread(&psi, sizeof(psi), 1, pFile) == 1)
563 {
564# if 0 /* 100% safe:*/
565 RTLogLoggerEx(pLogger, 0, ~0U, "Args: %s\n", psi.pr_psargs);
566# else /* probably safe: */
567 const char * const *argv = (const char * const *)psi.pr_argv;
568 for (int iArg = 0; iArg < psi.pr_argc; iArg++)
569 RTLogLoggerEx(pLogger, 0, ~0U, "Arg[%d]: %s\n", iArg, argv[iArg]);
570# endif
571
572 }
573 fclose(pFile);
574 }
575
576# elif defined(RT_OS_LINUX)
577 FILE *pFile = fopen("/proc/self/cmdline", "r");
578 if (pFile)
579 {
580 /* braindead */
581 unsigned iArg = 0;
582 int ch;
583 bool fNew = true;
584 while (!feof(pFile) && (ch = fgetc(pFile)) != EOF)
585 {
586 if (fNew)
587 {
588 RTLogLoggerEx(pLogger, 0, ~0U, "Arg[%u]: ", iArg++);
589 fNew = false;
590 }
591 if (ch)
592 RTLogLoggerEx(pLogger, 0, ~0U, "%c", ch);
593 else
594 {
595 RTLogLoggerEx(pLogger, 0, ~0U, "\n");
596 fNew = true;
597 }
598 }
599 if (!fNew)
600 RTLogLoggerEx(pLogger, 0, ~0U, "\n");
601 fclose(pFile);
602 }
603
604# elif defined(RT_OS_HAIKU)
605 team_info info;
606 if (get_team_info(0, &info) == B_OK)
607 {
608 /* there is an info.argc, but no way to know arg boundaries */
609 RTLogLoggerEx(pLogger, 0, ~0U, "Commandline: %.64s\n", info.args);
610 }
611
612# elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
613 /* Retrieve the required length first */
614 int aiName[4];
615# if defined(RT_OS_FREEBSD)
616 aiName[0] = CTL_KERN;
617 aiName[1] = KERN_PROC;
618 aiName[2] = KERN_PROC_ARGS; /* Introduced in FreeBSD 4.0 */
619 aiName[3] = getpid();
620# elif defined(RT_OS_NETBSD)
621 aiName[0] = CTL_KERN;
622 aiName[1] = KERN_PROC_ARGS;
623 aiName[2] = getpid();
624 aiName[3] = KERN_PROC_ARGV;
625# endif
626 size_t cchArgs = 0;
627 int rcBSD = sysctl(aiName, RT_ELEMENTS(aiName), NULL, &cchArgs, NULL, 0);
628 if (cchArgs > 0)
629 {
630 char *pszArgFileBuf = (char *)RTMemAllocZ(cchArgs + 1 /* Safety */);
631 if (pszArgFileBuf)
632 {
633 /* Retrieve the argument list */
634 rcBSD = sysctl(aiName, RT_ELEMENTS(aiName), pszArgFileBuf, &cchArgs, NULL, 0);
635 if (!rcBSD)
636 {
637 unsigned iArg = 0;
638 size_t off = 0;
639 while (off < cchArgs)
640 {
641 size_t cchArg = strlen(&pszArgFileBuf[off]);
642 RTLogLoggerEx(pLogger, 0, ~0U, "Arg[%u]: %s\n", iArg, &pszArgFileBuf[off]);
643
644 /* advance */
645 off += cchArg + 1;
646 iArg++;
647 }
648 }
649 RTMemFree(pszArgFileBuf);
650 }
651 }
652
653# elif defined(RT_OS_OS2) || defined(RT_OS_DARWIN)
654 /* commandline? */
655# else
656# error needs porting.
657# endif
658 }
659
660#else /* IN_RING0 */
661
662 /* Some platforms has trouble allocating memory with interrupts and/or
663 preemption disabled. Check and fail before we panic. */
664# if defined(RT_OS_DARWIN)
665 if ( !ASMIntAreEnabled()
666 || !RTThreadPreemptIsEnabled(NIL_RTTHREAD))
667 return NULL;
668# endif
669
670# ifndef IN_GUEST
671 rc = RTLogCreate(&pLogger, 0, NULL, "VBOX_LOG", RT_ELEMENTS(g_apszGroups), &g_apszGroups[0], RTLOGDEST_FILE, "VBox-ring0.log");
672# else /* IN_GUEST */
673 rc = RTLogCreate(&pLogger, 0, NULL, "VBOX_LOG", RT_ELEMENTS(g_apszGroups), &g_apszGroups[0], RTLOGDEST_USER, "VBox-ring0.log");
674# endif /* IN_GUEST */
675 if (RT_SUCCESS(rc))
676 {
677 /*
678 * This is where you set your ring-0 logging preferences.
679 *
680 * On platforms which don't differ between debugger and kernel
681 * log printing, STDOUT is gonna be a stub and the DEBUGGER
682 * destination is the one doing all the work. On platforms
683 * that do differ (like Darwin), STDOUT is the kernel log.
684 */
685# if defined(DEBUG_bird)
686 /*RTLogGroupSettings(pLogger, "all=~0 -default.l6.l5.l4.l3");*/
687 RTLogFlags(pLogger, "enabled unbuffered pid tid");
688 RTLogDestinations(pLogger, "debugger stdout");
689# ifdef IN_GUEST
690 /*RTLogGroupSettings(pLogger, "all=~0 -default.l6.l5.l4.l3");*/
691 RTLogGroupSettings(pLogger, "all=~0");
692# endif
693# endif
694# if defined(DEBUG_sandervl) && !defined(IN_GUEST)
695 RTLogGroupSettings(pLogger, "+all");
696 RTLogFlags(pLogger, "enabled unbuffered");
697 RTLogDestinations(pLogger, "debugger");
698# endif
699# if defined(DEBUG_ramshankar) /* Guest ring-0 as well */
700 RTLogGroupSettings(pLogger, "+all.e.l.f");
701 RTLogFlags(pLogger, "enabled unbuffered");
702 RTLogDestinations(pLogger, "debugger");
703# endif
704# if defined(DEBUG_aleksey) /* Guest ring-0 as well */
705 RTLogGroupSettings(pLogger, "net_flt_drv.e.l.f.l3.l4.l5.l6 +net_adp_drv.e.l.f.l3.l4.l5.l6");
706 RTLogFlags(pLogger, "enabled unbuffered");
707 RTLogDestinations(pLogger, "debugger stdout");
708# endif
709# if defined(DEBUG_andy) /* Guest ring-0 as well */
710 RTLogGroupSettings(pLogger, "+all.e.l.f");
711 RTLogFlags(pLogger, "enabled unbuffered pid tid");
712 RTLogDestinations(pLogger, "debugger stdout");
713# endif
714# if defined(DEBUG_misha) /* Guest ring-0 as well */
715 RTLogFlags(pLogger, "enabled unbuffered");
716 RTLogDestinations(pLogger, "debugger");
717# endif
718# if defined(DEBUG_michael) && defined(IN_GUEST)
719 RTLogGroupSettings(pLogger, "+vga.e.l.f");
720 RTLogFlags(pLogger, "enabled unbuffered");
721 RTLogDestinations(pLogger, "debugger stdout");
722# endif
723# if 0 /* vboxdrv logging - ATTENTION: this is what we're referring to guys! Change to '# if 1'. */
724 RTLogGroupSettings(pLogger, "all=~0 -default.l6.l5.l4.l3");
725 RTLogFlags(pLogger, "enabled unbuffered tid");
726 RTLogDestinations(pLogger, "debugger stdout");
727# endif
728 }
729#endif /* IN_RING0 */
730 return g_pLogger = RT_SUCCESS(rc) ? pLogger : NULL;
731}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use