aboutsummaryrefslogtreecommitdiff
path: root/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c
Commit message (Collapse)AuthorAgeFilesLines
* dtrace: Add the 'oformat' libdtrace optionDomagoj Stolfa2024-01-101-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This option can be used to specify a format to use in DTrace output. The following formats are supported: - json - xml - html - none (default DTrace output) This is implemented using libxo and integrated into libdtrace. Client code only works with the following API: - dtrace_oformat_setup(dtrace_hdl_t *) -- to be called when output is starting. - dtrace_oformat_teardown(dtrace_hdl_t *) -- to be called when output is finished - dtrace_oformat(dtrace_hdl_t *) -- check if oformat is enabled. - dtrace_set_outfp(FILE *) -- sets the output file for oformat. - Ensure that oformat is correctly checked in the drop handler and record processing callbacks. This commit also adds tests which check if the generated output is valid (JSON, XML) and extends the dtrace(1) describing the structured output. Reviewed by: markj Discussed with: phil MFC after: 2 months Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D41745
* dtrace: remove stray {Kristof Provost2023-01-241-1/+1
| | | | | Fixes: da81cc6035f8283b6adda1ef466977e8c1c5389e PR: 269128
* dtrace: conditionally load the systrace_linux klds when loading dtrace.Andrew Gallatin2023-01-241-0/+9
| | | | | | | | | | | | | | | | | | | When dtrace starts, it tries to detect if the dtrace klds are loaded, and if not, it loads them by loading the dtraceall kld. This module depends on most dtrace modules, including systrace for the native freebsd and freebsd32 ABIs. However, it does not depend on the systrace_linux klds, as they in turn depend on the linux ABI klds, and we don't want to load an ABI module that the user has not explicitly requested. This can leave a naive user in a state where they think all syscall providers have been loaded, yet linux ABI syscalls are "invisible" to dtrace. To fix this, check to see if the linux ABI modules are loaded. If they are, then load their systrace klds. Reviewed by: markj, (emaste & jhb, earlier versions) Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D37986
* libdtrace: Add kinst supportChristos Margiolis2022-10-111-0/+3
| | | | | | | | | | | | kinst does not instantiate its probes automatically, it only does so on demand via an ioctl interface implemented by /dev/kinst. This change modifies libdtrace to perform that work when the script references the kinst provider, similar to the way pid provider probes are implemented. Reviewed by: markj MFC after: 3 months Sponsored by: Google, Inc. (GSoC 2022) Differential Revision: https://reviews.freebsd.org/D36852
* dtrace: Add a "regs" variableMark Johnston2022-10-041-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | This allows invop-based providers (i.e., fbt and kinst) to expose the register file of the CPU at the point where the probe fired. It does not work for SDT providers because their probes are implemented as plain function calls and so don't save registers. It's not clear what semantics "regs" should have for them anyway. This is akin to "uregs", which nominally provides access to the userspace registers. In fact, DIF already had a DIF_VAR_REGS variable defined, it was simply unimplemented. Usage example: print the contents of %rdi upon each call to amd64_syscall(): fbt::amd64_syscall:entry {printf("%x", regs[R_RDI]);} Note that the R_* constants are defined in /usr/lib/dtrace/regs_x86.d. Currently there are no similar definitions for non-x86 platforms. Reviewed by: christos MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D36799
* libdtrace: Add a missing newline to an error messageMark Johnston2022-02-231-1/+1
| | | | | MFC after: 1 week Sponsored by: The FreeBSD Foundation
* Do not load dtraceall.ko if dtrace.ko is already loaded.Mark Johnston2020-02-281-1/+1
| | | | | | | | | | | | This was the intent of the existing code, but instead it would unconditionally load dtraceall.ko because of a stale errno value. Reported by: pho MFC after: 1 week Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=358435
* Disable the D subroutines msgsize() and msgdsize().Mark Johnston2018-08-101-1/+1
| | | | | | | | | | They are specific to illumos and the corresponding DIF subroutines are already disabled on FreeBSD. Reported by: gnn Notes: svn path=/head/; revision=337584
* Add "jid" and "jailname" variables to DTrace.Mark Johnston2018-01-121-2/+6
| | | | | | | | | | | | | | | | | These return the jail ID and jail name for the traced process, respectively, and are analogous to "zonename" on Solaris/illumos. "zonename" is now aliased to "jailname". Also add some stress tests for the new variables. Submitted by: Domagoj Stolfa <domagoj.stolfa@gmail.com> Reviewed by: dteske (previous version) MFC after: 2 weeks Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D13877 Notes: svn path=/head/; revision=327888
* Complete support for dtrace's -x setenv option.Mark Johnston2017-12-031-4/+5
| | | | | | | | | | | | | | This allows one to override the environment for processes created with dtrace -c. By default, the environment is inherited. This support was originally merged from illumos in r249367 but was lost when the commit was later reverted and then brought back piecemeal. Reported by: Samuel Lepetit <slepetit@apple.com> MFC after: 2 weeks Notes: svn path=/head/; revision=326499
* Fix the type signature for sx(9) DTrace subroutines.Mark Johnston2017-11-241-1/+1
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=326177
* Add a O_CLOEXEC use missed in r323166.Mark Johnston2017-09-121-1/+1
| | | | | | | | | PR: 199810 Reported by: Jukka A. Ukkonen <jau789@gmail.com> MFC after: 3 days Notes: svn path=/head/; revision=323498
* Use O_CLOEXEC when opening persistent handles in libdtrace.Mark Johnston2017-09-051-6/+3
| | | | | | | | | PR: 199810 Submitted by: jau@iki.fi MFC after: 1 week Notes: svn path=/head/; revision=323166
* Fix memory leaks in error cases in libdtrace.Mark Johnston2017-02-231-2/+6
| | | | | | | | | Submitted by: Tom Rix <trix@juniper.net> MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D9705 Notes: svn path=/head/; revision=314154
* Remove the DTrace printt and typeref actions.Mark Johnston2016-11-121-4/+0
| | | | | | | | | | | | | These are FreeBSD-specific and were added in r178576 to provide the ability to pretty-print instances of compound types. However, the print action has long since been augmented to provide this functionality with a simpler interface. Discussed with: gnn Differential Revision: https://reviews.freebsd.org/D8478 Notes: svn path=/head/; revision=308582
* MFV r304057:Mark Johnston2016-08-161-3/+5
| | | | | | | | | | | | | | | | | | | | | | | 7085 add support for "if" and "else" statements in dtrace illumos/illumos-gate@c3bd3abd8856e8e75d820f65c58031cd6cbac818 Add syntactic sugar to dtrace: "if" and "else" statements. The sugar is baked down to standard dtrace features by adding additional clauses with the appropriate predicates. Reviewed by: Adam Leventhal <ahl@delphix.com> Reviewed by: Sebastien Roy <sebastien.roy@delphix.com> Reviewed by: Paul Dagnelie <pcd@delphix.com> Reviewed by: Bryan Cantrill <bryan@joyent.com> Approved by: Richard Lowe <richlowe@richlowe.net> Author: Matthew Ahrens <mahrens@delphix.com> MFC after: 2 weeks Relnotes: yes Notes: svn path=/head/; revision=304200
* libdtrace: allow D libraries to declare dependencies on kernel modulesMark Johnston2015-06-061-0/+20
| | | | | | | | | | | | | | | The "depends_on module" pragma can be used to declare a dependency on a DTrace module, which for kernel probes corresponds to a KLD. Such dependencies cannot be checked if the KLD is compiled into the kernel. Therefore, allow a module dependency to be satisfied if either a kernel module or a KLD with the specified name is loaded. Differential Revision: https://reviews.freebsd.org/D2653 Reviewed by: gnn, rpaulo Reported by: gnn Notes: svn path=/head/; revision=284085
* Respect the libdir option when linking drti.o, rather than hardcoding theMark Johnston2015-05-171-0/+12
| | | | | | | | | default path of /usr/lib(32)/dtrace. MFC after: 3 weeks Notes: svn path=/head/; revision=283038
* Remove drti.o's dependency on libelf. This makes it possible to add DTraceMark Johnston2015-02-181-0/+10
| | | | | | | | | | | | | | | | | | | | | | probes to userland programs and libraries without also needing to link libelf. dtrace -G places the __SUNW_dof symbol at the beginning of the DOF (DTrace probe and provider metdata) section in the generated object file; drti.o now just uses this symbol to locate the section. A complication occurs when multiple dtrace-generated object files are linked together, since the __SUNW_dof symbol defined in each file is global. This is handled by using objcopy(1) to convert __SUNW_dof to a local symbol once drti.o has been linked with the generated object file. Upstream, this is done using a linker feature not present in GNU ld. Differential Revision: https://reviews.freebsd.org/D1757 Reviewed by: rpaulo MFC after: 1 month Relnotes: yes Notes: svn path=/head/; revision=278934
* Mechanically convert cddl sun #ifdef's to illumosSteven Hartland2015-01-171-28/+27
| | | | | | | | | | | | | | | Since the upstream for cddl code is now illumos not sun, mechanically convert all sun #ifdef's to illumos #ifdef's which have been used in all newer code for some time. Also do a manual pass to correct the use if #ifdef comments as per style(9) as well as few uses of #if defined(__FreeBSD__) vs #ifndef illumos. MFC after: 1 month Sponsored by: Multiplay Notes: svn path=/head/; revision=277300
* Make DTrace stuff compile with C99 standard.Xin LI2014-08-221-0/+5
| | | | Notes: svn path=/head/; revision=270358
* MFV illumosRui Paulo2014-06-261-2/+5
| | | | | | | | | | | 4471 DTrace count() with histogram 4472 DTrace full width distribution histograms 4473 DTrace frequency trails MFC after: 2 weeks Notes: svn path=/head/; revision=267942
* MFV illumosRui Paulo2014-06-261-3/+5
| | | | | | | | | | | | | 4474 DTrace Userland CTF Support 4475 DTrace userland Keyword 4476 DTrace tests should be better citizens 4479 pid provider types 4480 dof emulation is missing checks MFC after: 2 weeks Notes: svn path=/head/; revision=267941
* MFV illumosRui Paulo2014-06-261-2/+8
| | | | | | | | | 4477 DTrace should speak JSON MFC after: 2 weeks Notes: svn path=/head/; revision=267937
* MFV illumos r266986:Rui Paulo2014-06-261-3/+7
| | | | | | | | | | | 2915 DTrace in a zone should see "cpu", "curpsinfo", et al 2916 DTrace in a zone should be able to access fds[] 2917 DTrace in a zone should have limited provider access MFC after: 2 weeks Notes: svn path=/head/; revision=267929
* Revert r267898.Rui Paulo2014-06-261-14/+3
| | | | Notes: svn path=/head/; revision=267925
* Bring the following change from the illumos-joyent repository:Rui Paulo2014-06-261-3/+14
| | | | | | | | | | | | | | | commit 78e24ab6803bbe11ba37642624e1498ede5b239d Author: Bryan Cantrill <bryan@joyent.com> Date: Thu Oct 31 01:20:54 2013 OS-1688 DTrace count() with histogram OS-2360 DTrace full width distribution histograms OS-2361 DTrace frequency trails MFC after: 2 weeks Notes: svn path=/head/; revision=267898
* Re-apply r248644. This fixes an annoying problem which caused dtrace -c toMark Johnston2014-05-081-1/+1
| | | | | | | | | | | | | | fail to attach to stripped binaries. With the _r_debug_postinit symbol, dtrace(1) can now set a breakpoint in the victim process after it has registered its DOF table(s) with the kernel. r_debug_state cannot be used for this purpose since it is called before DOF is made available, in which case dtrace(1) cannot create USDT probes before the program begins execution. MFC after: 2 weeks Notes: svn path=/head/; revision=265631
* The uaddr, ufunc, umod and usym functions all seem to work as expected onMark Johnston2013-12-041-8/+0
| | | | | | | | | FreeBSD, so stop hiding them behind a "#if defined(sun)". Reported by: Prashanth Kumar <pra_udupi@yahoo.co.in> Notes: svn path=/head/; revision=258902
* Add a function, memstr, which can be used to convert a buffer ofMark Johnston2013-10-161-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | null-separated strings to a single string. This can be used to print the full arguments of a process using execsnoop (from the DTrace toolkit) or with the following one-liner: dtrace -n 'syscall::execve:return {trace(curpsinfo->pr_psargs);}' Note that this relies on the process arguments being cached via the struct proc, which means that it will not work for argvs longer than kern.ps_arg_cache_limit. However, the following rather non-portable script can be used to extract any argv at exec time: fbt::kern_execve:entry { printf("%s", memstr(args[1]->begin_argv, ' ', args[1]->begin_envv - args[1]->begin_argv)); } The debug.dtrace.memstr_max sysctl limits the maximum argument size to memstr(). Thanks to Brendan Gregg for helpful comments on freebsd-dtrace. Tested by: Fabian Keil (earlier version) MFC after: 2 weeks Notes: svn path=/head/; revision=256571
* Load the dtraceall module if /dev/dtrace/dtrace doesn't exist.Rui Paulo2013-08-101-1/+11
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=254197
* Bring back part of r249367 by adding DTrace's temporal option, which allowsMark Johnston2013-05-121-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | users to guarantee that the output of DTrace scripts will be time-ordered. This option is enabled by adding the line #pragma D option temporal to the beginning of a script, or by adding '-x temporal' to the arguments of dtrace(1). This change fixes a bug in the original port of the temporal option. This bug was causing some assertions to fail, so they had been disabled; in this revision the assertions are working properly and are enabled. The DTrace version number has been bumped from 1.9.0 to 1.9.1 to reflect the language change that's being introduced. This change corresponds to part of illumos-gate commit e5803b76927480: 3021 option for time-ordered output from dtrace(1M) Reviewed by: pfg Obtained from: illumos MFC after: 1 month Notes: svn path=/head/; revision=250574
* revert r248644 because of the regression for usdt probesAndriy Gapon2013-04-251-1/+1
| | | | | | | | | | | | | | | | | | USDT probes are advertised to kernel by initialization code with atrribute((constructor))). It seems that on Solaris the .init-ish code of the main object is executed before RD_PREINIT point is hit. On FreeBSD that is not the case. And because on FreeBSD there is no other well-defined point between RD_PREINIT and main() we have to parse a DTrace script when main is hit, for time being. A footnote: currently we actually post RD_POSTINIT event, but that's a bug because the event is triggered by hitting r_debug_state which happens before any init code is executed. Reported by: markj Notes: svn path=/head/; revision=249884
* DTrace: Revert r249367Pedro F. Giffuni2013-04-171-11/+9
| | | | | | | | | | | | | | | | | | | | | | | | | The following change from illumos brought caused DTrace to pause in an interactive environment: 3026 libdtrace should set LD_NOLAZYLOAD=1 to help the pid provider This was not detected during testing because it doesn't affect scripts. We shouldn't be changing the environment, especially since the LD_NOLAZYLOAD option doesn't apply to our (GNU) ld. Unfortunately the change from upstream was made in such a way that it is very difficult to separate this change from the others so, at least for now, it's better to just revert everything. Reference: https://www.illumos.org/issues/3026 Reported by: Navdeep Parhar and Mark Johnston Notes: svn path=/head/; revision=249573
* DTrace: option for time-ordered outputPedro F. Giffuni2013-04-111-9/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Merge changes from illumos: 3021 option for time-ordered output from dtrace(1M) 3022 DTrace: keys should not affect the sort order when sorting by value 3023 it should be possible to dereference dynamic variables 3024 D integer narrowing needs some work 3025 register leak in D code generation 3026 libdtrace should set LD_NOLAZYLOAD=1 to help the pid provider This brings yet another feature implemented in upstream DTrace. A complete description is available here: http://dtrace.org/blogs/ahl/2012/07/28/my-new-dtrace-favorite/ This change bumps the DT_VERS_* number to 1.9.1 in accordance to what is done in illumos. This change was somewhat complicated because upstream is mixed many changes in an individual commit and some of the tests don't really apply to us. There are also appear to be differences in timestamping with Solaris so we had to workaround some assertions making sure no regression happened. Special thanks to Fabian Keil for changes and testing. Illumos Revisions: 13758:23432da34147 Reference: https://www.illumos.org/issues/3021 https://www.illumos.org/issues/3022 https://www.illumos.org/issues/3023 https://www.illumos.org/issues/3024 https://www.illumos.org/issues/3025 https://www.illumos.org/issues/1694 Tested by: Fabian Keil Obtained from: Illumos MFC after: 1 months Notes: svn path=/head/; revision=249367
* Dtrace: Add SUN MDB-like type-aware print() action.Pedro F. Giffuni2013-03-251-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Merge change from illumos: 1694 Add type-aware print() action This is a very nice feature implemented in upstream Dtrace. A complete description is available here: http://dtrace.org/blogs/eschrock/2011/10/26/your-mdb-fell-into-my-dtrace/ This change bumps the DT_VERS_* number to 1.9.0 in accordance to what is done in illumos. While here also include some minor cleanups to ease further merging and appease clang with a fix by Fabian Keil. Illumos Revisions: 13501:c3a7090dbc16 13483:f413e6c5d297 Reference: https://www.illumos.org/issues/1560 https://www.illumos.org/issues/1694 Tested by: Fabian Keil Obtained from: Illumos MFC after: 1 month Notes: svn path=/head/; revision=248708
* Dtrace: add toupper()/tolower() and enhancements to lltostr().Pedro F. Giffuni2013-03-251-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Merge changes from illumos: 1451 DTrace needs toupper()/tolower() subroutines 1457 lltostr() D subroutine should take an optional base This change bumps the DT_VERS_* number to 1.8.1 in accordance to what is done in illumos. The test suite we currently include is outdated and doesnt support some updates in tst.subr.d which had to be left out for now. Illumos Revisions: r13458 5e394d8db762 r13459 c3454574dd1a Reference: https://www.illumos.org/issues/1451 https://www.illumos.org/issues/1457 Tested by: Fabian Keil Obtained from: Illumos MFC after: 1 month Notes: svn path=/head/; revision=248706
* Dtrace: add optional size argument to tracemem().Pedro F. Giffuni2013-03-241-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Merge change from illumos: 1455 DTrace tracemem() should take an optional size argument Our local enhancements to dt_print_bytes were equivalent to those in illumos but we made it match the illumos version to ease further code merges. For now leave out tst.smallsize.d and tst.smallsize.d.out since those don't seem to work cleanly on FreeBSD. This change bumps the DT_VERS_* number to 1.7.1 in accordance to what is done in illumos. Illumos Revision: 13457:571b0355c2e3 Reference: https://www.illumos.org/issues/1455 Tested by: Fabian Keil Obtained from: Illumos MFC after: 1 month Notes: svn path=/head/; revision=248690
* dtrace: ensure that we can always catch a process (e.g. when -c is used)Andriy Gapon2013-03-231-1/+1
| | | | | | | | | | | | It is not guaranteed that a program has a symbol table entry for main and thus that it would be possible to set a breakpoint on it. Reviewed by: rpaulo Discussed with: rpaulo MFC after: 13 days Notes: svn path=/head/; revision=248644
* Bring llquantize support into Dtrace.Pedro F. Giffuni2012-06-271-2/+8
| | | | | | | | | | | | | | | | | | | | | Bryan Cantrill implemented the equivalent of semi-log graph paper for Dtrace so llquantize will use one logarithmic and one linear scale. Special thanks to Mark Peek for providing fix to an assertion and to Fabian Keill for testing the port. Illumos Revision: 13355:15b74a2a9a9d Reference: https://www.illumos/issues/905 Obtained from: Illumos Tested by: Fabian Keill, mp MFC after: 4 days Notes: svn path=/head/; revision=237624
* Implement the D "cpu" variable, which returns curcpu. I have chosen notRyan Stone2012-04-261-0/+6
| | | | | | | | | | | | | | to follow the example of OpenSolaris and its descendants, which implemented cpu as an inline that took a value out of curthread. At certain points in the FreeBSD scheduler curthread->td_oncpu will no longer be valid (in particukar, just before the thread gets descheduled) so instead I have implemented this as its own built-in variable. Sponsored by: Sandvine Inc. MFC after: 1 week Notes: svn path=/head/; revision=234691
* Give a chance to the target binary to run the ctors by waiting until itRui Paulo2010-09-121-1/+1
| | | | | | | | | has reached main(). This allows plockstat to work. Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=212495
* Add libdtrace support for tracing userland programs.Rui Paulo2010-08-211-6/+8
| | | | | | | | | | | | | | | | | | | | | Summary of changes: * Implement a compatibility shim between Solaris libproc and our libproc and remove several ifdefs because of this. * Port the drti to FreeBSD. * Implement the missing DOODAD sections * Link with libproc and librtld_db * Support for ustack, jstack and uregs (by sson@) * Misc bugfixing When writing the SUWN_dof section, we had to resort to building the ELF file layout by "hand". This is the job of libelf, but our libelf doesn't support this yet. When libelf is fixed, we can remove the code under #ifdef BROKEN_LIBELF. Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=211554
* MFV OpenSolaris DTrace userland bits.Rui Paulo2010-08-021-6/+5
| | | | Notes: svn path=/head/; revision=210767
* Merge latest DTrace changes from Perforce.Craig Rodrigues2008-11-051-2/+4
| | | | | | | Approved by: jb Notes: svn path=/head/; revision=184696
* * Add FreeBSD action extensions.John Birrell2008-04-261-6/+267
| | | | | | | | | | * Get the kernel module file name rather than hard-coding it like on Solaris. * Use FreeBSD's process library API. * Handle FreeBSD's different lock types. * Get the list of loaded providers via a syscall. Notes: svn path=/head/; revision=178570
* This commit was generated by cvs2svn to compensate for changes in r178528,John Birrell2008-04-261-267/+6
| | | | | | | which included commits to RCS files with non-trunk default branches. Notes: svn path=/head/; revision=178529
* This commit was generated by cvs2svn to compensate for changes in r178479,John Birrell2008-04-251-0/+1643
which included commits to RCS files with non-trunk default branches. Notes: svn path=/head/; revision=178480