b1b3e34b88
Dart VM changes: Note that the following changes are backwards compatible in the case that a Dart program has no deferred loading units (i.e., the Dart program is contained in a single shared object snapshot). When there are non-root loading units, the non-symbol stack trace header now includes information about loading units as follows: loading_unit: N, build_id: S, dso_base: A, instructions: A where N is an integer, S is a string of hex digits (0-9a-f), and A is a word-sized address printed as a hex string (without prefix). In addition, all non-symbolic stack frames for isolate instructions include a unit field, including those for the root loading unit, e.g., #NN abs <address> unit <id> virt <address> <symbol>+<offset> If there are no non-root loading units, then the non-symbolic stack trace is unchanged from its previous format. Adds a build ID to split deferred loading unit snapshots. Fixes: https://github.com/dart-lang/sdk/issues/43516 If separate debugging information is requested, the loading unit manifest includes a 'debugPath' field for each loading unit, which contains the path to its separate debugging information. Removes the attempt to store the relocated address of the instructions section when running from an assembled snapshot in the initialized BSS. Adds OS::GetAppDSOBase, which takes a pointer to the instructions section and returns a pointer to its loaded shared object in memory. For compiled-to-ELF snapshots, it does this using the relocated address of the instructions in the Image, and for assembled snapshots, it delegates to NativeSymbolResolver::LookupSharedObject. ----- Changes to package:native_stack_traces: PCOffset now has two new fields: * int? unitId: the unit ID of the loading unit, when available. * String? buildId: the build ID of the loading unit, when available. For PCOffsets in the VM section, the unitId and buildId are those of the root loading unit. The constructor for the DwarfStackTraceDecoder now takes two additional optional named arguments: * Map<int, Dwarf>? dwarfByUnitId: A map associating loading unit IDs with the appropriate Dwarf object. May or may not contain an entry for the root loading unit. * Iterable<Dwarf>? unitDwarfs: An iterable container holding Dwarf objects. May or may not contain an entry for the root loading unit. The Dwarf object that is passed to the DwarfStackTraceDecoder as a positional argument is used for all lookups within the root loading unit. If the dwarfByUnitId or unitDwarfs arguments contain an entry for the root loading unit, it should be the same as the positional argument. When decoding a non-symbolic stack frame with a non-root loading unit id, the decoder first looks in the map for the appropriate Dwarf object. If one is not found, the decoder uses the build ID for the loading unit to find the appropriate Dwarf object in the iterable container. If an appropriate Dwarf object cannot be found in either manner, the non-symbolic stack frame is emitted without change. The native_stack_traces:decode executable now takes two additional multi-options for the translate command: * -u, --unit_debug: Takes a path to the associated DWARF information. * --unit_id_debug: Takes N=FILE, where N is the loading unit ID and FILE is a path to the associated DWARF information. The arguments to -u are collected into an iterable container to be passed as the unitDwarfs argument to the DwarfStackTraceDecoder, and the arguments to --unit-id-debug are collected into a map to be passed as the dwarfByUnitId argument. TEST=vm/dart/use_dwarf_stack_traces_flag_deferred Issue: https://github.com/dart-lang/sdk/issues/53902 Change-Id: I210d4f69e4ae9fd37275a96beb1aac55c5e9d080 Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-product-arm64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362380 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Tess Strickland <sstrickl@google.com>
148 lines
5.2 KiB
C++
148 lines
5.2 KiB
C++
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#ifndef RUNTIME_VM_OS_H_
|
|
#define RUNTIME_VM_OS_H_
|
|
|
|
#include "vm/globals.h"
|
|
|
|
// Forward declarations.
|
|
struct tm;
|
|
|
|
namespace dart {
|
|
|
|
// Forward declarations.
|
|
class Zone;
|
|
|
|
// Interface to the underlying OS platform.
|
|
class OS {
|
|
public:
|
|
// Returns the name of the given OS. For example "linux".
|
|
static const char* Name() { return kHostOperatingSystemName; }
|
|
|
|
// Returns the current process id.
|
|
static intptr_t ProcessId();
|
|
|
|
// Returns a time-zone name for the given instant.
|
|
// The name is provided by the underlying platform.
|
|
// The returned string may be Zone allocated.
|
|
static const char* GetTimeZoneName(int64_t seconds_since_epoch);
|
|
|
|
// Returns the difference in seconds between local time and UTC for the given
|
|
// instant.
|
|
// For example 3600 for CET, and 7200 for CEST.
|
|
static int GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch);
|
|
|
|
// Returns the current time in milliseconds measured
|
|
// from midnight January 1, 1970 UTC.
|
|
static int64_t GetCurrentTimeMillis();
|
|
|
|
// Returns the current time in microseconds measured
|
|
// from midnight January 1, 1970 UTC.
|
|
static int64_t GetCurrentTimeMicros();
|
|
|
|
// Returns the current time used by the tracing infrastructure.
|
|
static int64_t GetCurrentMonotonicMicros();
|
|
|
|
// Returns the raw clock value from the monotonic clock.
|
|
static int64_t GetCurrentMonotonicTicks();
|
|
|
|
// Returns the frequency of the monotonic clock.
|
|
static int64_t GetCurrentMonotonicFrequency();
|
|
|
|
// Returns the value of current thread's CPU usage clock in microseconds.
|
|
// NOTE: This clock will return different values depending on the calling
|
|
// thread. It is only expected to increase in value as the thread uses
|
|
// CPU time.
|
|
// NOTE: This function will return -1 on OSs that are not supported.
|
|
static int64_t GetCurrentThreadCPUMicros();
|
|
|
|
// If the tracing/timeline configuration on takes timestamps as input, returns
|
|
// the same value as |GetCurrentMonotonicMicros|. Otherwise, returns -1.
|
|
static int64_t GetCurrentMonotonicMicrosForTimeline();
|
|
|
|
// Returns the activation frame alignment constraint or one if
|
|
// the platform doesn't care. Guaranteed to be a power of two.
|
|
static intptr_t ActivationFrameAlignment();
|
|
|
|
// Returns number of available processor cores.
|
|
static int NumberOfAvailableProcessors();
|
|
|
|
// Sleep the currently executing thread for millis ms.
|
|
static void Sleep(int64_t millis);
|
|
|
|
// Sleep the currently executing thread for micros microseconds.
|
|
static void SleepMicros(int64_t micros);
|
|
|
|
// Debug break.
|
|
static void DebugBreak();
|
|
|
|
// Returns the current program counter.
|
|
static uintptr_t GetProgramCounter();
|
|
|
|
// Print formatted output to stdout/stderr for debugging.
|
|
// Tracing and debugging prints from the VM should strongly prefer to use
|
|
// PrintErr to avoid interfering with the application's output, which may
|
|
// be parsed by another program.
|
|
static void Print(const char* format, ...) PRINTF_ATTRIBUTE(1, 2);
|
|
static void PrintErr(const char* format, ...) PRINTF_ATTRIBUTE(1, 2);
|
|
static void VFPrint(FILE* stream, const char* format, va_list args);
|
|
|
|
// Allocate a string and print formatted output into the buffer.
|
|
// Uses the zone for allocation if one if provided, and otherwise uses
|
|
// malloc.
|
|
static char* SCreate(Zone* zone, const char* format, ...)
|
|
PRINTF_ATTRIBUTE(2, 3);
|
|
static char* VSCreate(Zone* zone, const char* format, va_list args);
|
|
|
|
// Converts a C string which represents a valid dart integer into a 64 bit
|
|
// value.
|
|
// Returns false if it is unable to convert the string to a 64 bit value,
|
|
// the failure could be because of underflow/overflow or invalid characters.
|
|
// On success the function returns true and 'value' contains the converted
|
|
// value.
|
|
static bool StringToInt64(const char* str, int64_t* value);
|
|
|
|
// Register code observers relevant to this OS.
|
|
static void RegisterCodeObservers();
|
|
|
|
// Initialize the OS class.
|
|
static void Init();
|
|
|
|
// Cleanup the OS class.
|
|
static void Cleanup();
|
|
|
|
// Only implemented on Windows, prevents cleanup code from running.
|
|
static void PrepareToAbort();
|
|
|
|
DART_NORETURN static void Abort();
|
|
|
|
DART_NORETURN static void Exit(int code);
|
|
|
|
// Retrieves the DSO base for the given instructions image.
|
|
static const uint8_t* GetAppDSOBase(const uint8_t* snapshot_instructions);
|
|
static uword GetAppDSOBase(uword snapshot_instructions) {
|
|
return reinterpret_cast<uword>(
|
|
GetAppDSOBase(reinterpret_cast<const uint8_t*>(snapshot_instructions)));
|
|
}
|
|
|
|
struct BuildId {
|
|
intptr_t len;
|
|
const uint8_t* data;
|
|
};
|
|
|
|
// Retrieves the build ID information for the given instructions image.
|
|
// If found, returns a BuildId with the length of the build ID and a pointer
|
|
// to its contents, otherwise returns a BuildId with contents {0, nullptr}.
|
|
static BuildId GetAppBuildId(const uint8_t* snapshot_instructions);
|
|
static BuildId GetAppBuildId(uword snapshot_instructions) {
|
|
return GetAppBuildId(
|
|
reinterpret_cast<const uint8_t*>(snapshot_instructions));
|
|
}
|
|
};
|
|
|
|
} // namespace dart
|
|
|
|
#endif // RUNTIME_VM_OS_H_
|