1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
12 #include "AutoObjectMapper.h"
13 #include "BaseProfiler.h"
14 #include "SharedLibraries.h"
16 #include "PlatformMacros.h"
19 // Contains miscellaneous helpers that are used to connect the Gecko Profiler
22 // Find out, in a platform-dependent way, where the code modules got
23 // mapped in the process' virtual address space, and get |aLUL| to
24 // load unwind info for them.
25 void read_procmaps(lul::LUL
* aLUL
) {
26 MOZ_ASSERT(aLUL
->CountMappings() == 0);
28 #if defined(GP_OS_linux) || defined(GP_OS_android) || defined(GP_OS_freebsd)
29 SharedLibraryInfo info
= SharedLibraryInfo::GetInfoForSelf();
31 for (size_t i
= 0; i
< info
.GetSize(); i
++) {
32 const SharedLibrary
& lib
= info
.GetEntry(i
);
34 std::string nativePath
= lib
.GetDebugPath();
36 // We can use the standard POSIX-based mapper.
37 AutoObjectMapperPOSIX
mapper(aLUL
->mLog
);
39 // Ask |mapper| to map the object. Then hand its mapped address
40 // to NotifyAfterMap().
41 void* image
= nullptr;
43 bool ok
= mapper
.Map(&image
, &size
, nativePath
);
44 if (ok
&& image
&& size
> 0) {
45 aLUL
->NotifyAfterMap(lib
.GetStart(), lib
.GetEnd() - lib
.GetStart(),
46 nativePath
.c_str(), image
);
47 } else if (!ok
&& lib
.GetDebugName().empty()) {
48 // The object has no name and (as a consequence) the mapper failed to map
49 // it. This happens on Linux, where GetInfoForSelf() produces such a
50 // mapping for the VDSO. This is a problem on x86-{linux,android} because
51 // lack of knowledge about the mapped area inhibits LUL's special
52 // __kernel_syscall handling. Hence notify |aLUL| at least of the
53 // mapping, even though it can't read any unwind information for the area.
54 aLUL
->NotifyExecutableArea(lib
.GetStart(), lib
.GetEnd() - lib
.GetStart());
57 // |mapper| goes out of scope at this point and so its destructor
62 # error "Unknown platform"
66 // LUL needs a callback for its logging sink.
67 void logging_sink_for_LUL(const char* str
) {
68 // These are only printed when Verbose logging is enabled (e.g. with
69 // MOZ_BASE_PROFILER_VERBOSE_LOGGING=1). This is because LUL's logging is much
70 // more verbose than the rest of the profiler's logging, which occurs at the
71 // Info (3) and Debug (4) levels.
72 // FIXME: This causes a build failure in memory/replace/dmd/test/SmokeDMD (!)
73 // and other places, because it doesn't link the implementation in
75 // VERBOSE_LOG("[%d] %s", profiler_current_process_id(), str);