dart-sdk/runtime/bin/platform.h
Tess Strickland 24683da915 [vm] Add OS and architecture to non-symbolic stack traces.
Examples of the new line added to non-symbolic stack traces:

os: linux arch: x64 comp: yes sim: no
(Running on linux-x64c)

os: macos arch: arm64 comp: no sim: yes
(Running on mac-simarm64)

This CL also abstracts out the separate hardcoded strings across
the codebase for host and target OS and architecture into
definitions in platform/globals.h to ensure that they stay
in sync across different uses.

TEST=vm/dart{,_2}/use_dwarf_stack_traces_flag

Issue: https://github.com/flutter/flutter/pull/101586
Change-Id: Ifdfea5138dd1003f561da0174e89aebc165bf9b0
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-dwarf-linux-product-x64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm_x64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-mac-product-x64-try,vm-kernel-precomp-nnbd-linux-release-x64-try,vm-kernel-precomp-nnbd-linux-release-simarm_x64-try,vm-kernel-precomp-win-release-x64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try,vm-kernel-precomp-mac-release-simarm64-try,vm-ffi-android-release-arm-try,vm-ffi-android-release-arm64c-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/253283
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2022-08-05 11:53:37 +00:00

126 lines
4.3 KiB
C++

// Copyright (c) 2012, 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_BIN_PLATFORM_H_
#define RUNTIME_BIN_PLATFORM_H_
#include "bin/builtin.h"
#include "platform/atomic.h"
#include "platform/globals.h"
#include "platform/utils.h"
#if defined(DART_HOST_OS_MACOS)
#include "bin/platform_macos.h"
#endif // defined(DART_HOST_OS_MACOS)
namespace dart {
namespace bin {
class Platform {
public:
// Perform platform specific initialization.
static bool Initialize();
// Returns the number of processors on the machine.
static int NumberOfProcessors();
// Returns a string representing the operating system ("linux",
// "macos", "windows", or "android"). The returned string should not be
// deallocated by the caller.
static const char* OperatingSystem() { return kHostOperatingSystemName; }
// Returns a string representing the version of the operating system. The
// format of the string is determined by the platform. The returned string
// should not be deallocated by the caller.
static const char* OperatingSystemVersion();
// Returns the architecture name of the processor the VM is running on
// (ia32, x64, arm, or arm64).
static const char* HostArchitecture() { return kHostArchitectureName; }
static const char* LibraryPrefix();
// Returns a string representing the operating system's shared library
// extension (e.g. 'so', 'dll', ...). The returned string should not be
// deallocated by the caller.
static const char* LibraryExtension();
// Extracts the local hostname.
static bool LocalHostname(char* buffer, intptr_t buffer_length);
static const char* LocaleName();
// Extracts the environment variables for the current process. The array of
// strings is Dart_ScopeAllocated. The number of elements in the array is
// returned in the count argument.
static char** Environment(intptr_t* count);
static const char* ResolveExecutablePath();
// This has the same effect as calling ResolveExecutablePath except that
// Dart_ScopeAllocate is not called and that the result goes into the given
// parameters.
// WARNING: On Fuchsia it returns -1, i.e. doesn't work.
// Note that `result` should be pre-allocated with size `result_size`.
// The return-value is the length read into `result` or -1 on failure.
static intptr_t ResolveExecutablePathInto(char* result, size_t result_size);
// Stores the executable name.
static void SetExecutableName(const char* executable_name) {
executable_name_ = executable_name;
}
static const char* GetExecutableName();
static const char* GetResolvedExecutableName() {
if (resolved_executable_name_.load() == nullptr) {
// Try to resolve the executable path using platform specific APIs.
const char* resolved_name = Platform::ResolveExecutablePath();
if (resolved_name != nullptr) {
char* resolved_name_copy = Utils::StrDup(resolved_name);
const char* expect_old_is_null = nullptr;
if (!resolved_executable_name_.compare_exchange_strong(
expect_old_is_null, resolved_name_copy)) {
free(resolved_name_copy);
}
}
}
return resolved_executable_name_.load();
}
// Stores and gets the flags passed to the executable.
static void SetExecutableArguments(int script_index, char** argv) {
script_index_ = script_index;
argv_ = argv;
}
static int GetScriptIndex() { return script_index_; }
static char** GetArgv() { return argv_; }
static void SetProcessName(const char* name);
DART_NORETURN static void Exit(int exit_code);
static void SetCoreDumpResourceLimit(int value);
private:
// The path to the executable.
static const char* executable_name_;
// The path to the resolved executable.
//
// We use require-release semantics to ensure initializing stores to the
// string are visible when the string becomes visible.
static AcqRelAtomic<const char*> resolved_executable_name_;
static int script_index_;
static char** argv_; // VM flags are argv_[1 ... script_index_ - 1]
DISALLOW_ALLOCATION();
DISALLOW_IMPLICIT_CONSTRUCTORS(Platform);
};
} // namespace bin
} // namespace dart
#endif // RUNTIME_BIN_PLATFORM_H_