зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1471347 - part 2 - store an nsCString for SharedLibrary::mBreakpadId; r=njn
Similar to the previous part, we convert mBreakpadId to an nsCString to avoid issues with locale-dependent std::string operations. There are a lot of non-profiler changes here because a bunch of things depend on the SharedLibrary object that the profiler defines.
This commit is contained in:
Родитель
0115588ec9
Коммит
6026bc4fec
|
@ -367,8 +367,7 @@ ReadModuleInformation(HangStack& stack)
|
|||
}
|
||||
|
||||
if (moduleReferenced) {
|
||||
nsDependentCString cstr(info.GetBreakpadId().c_str());
|
||||
HangModule module(info.GetDebugName(), cstr);
|
||||
HangModule module(info.GetDebugName(), info.GetBreakpadId());
|
||||
stack.modules().AppendElement(module);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -167,7 +167,7 @@ CreateJSStackObject(JSContext *cx, const CombinedStacks &stacks) {
|
|||
}
|
||||
|
||||
// Module breakpad identifier
|
||||
JS::Rooted<JSString*> id(cx, JS_NewStringCopyZ(cx, module.mBreakpadId.c_str()));
|
||||
JS::Rooted<JSString*> id(cx, JS_NewStringCopyZ(cx, module.mBreakpadId.get()));
|
||||
if (!id || !JS_DefineElement(cx, moduleInfoArray, index++, id, JSPROP_ENUMERATE)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
// The file name, /foo/bar/libxul.so for example.
|
||||
// It can contain unicode characters.
|
||||
nsString mName;
|
||||
std::string mBreakpadId;
|
||||
nsCString mBreakpadId;
|
||||
|
||||
bool operator==(const Module& other) const;
|
||||
};
|
||||
|
|
|
@ -794,8 +794,8 @@ public:
|
|||
// Module Breakpad identifier.
|
||||
JS::RootedValue id(cx);
|
||||
|
||||
if (!info.GetBreakpadId().empty()) {
|
||||
JS::RootedString str_id(cx, JS_NewStringCopyZ(cx, info.GetBreakpadId().c_str()));
|
||||
if (!info.GetBreakpadId().IsEmpty()) {
|
||||
JS::RootedString str_id(cx, JS_NewStringCopyZ(cx, info.GetBreakpadId().get()));
|
||||
if (!str_id) {
|
||||
mPromise->MaybeReject(NS_ERROR_FAILURE);
|
||||
return NS_OK;
|
||||
|
@ -990,7 +990,7 @@ ReadStack(PathCharPtr aFileName, Telemetry::ProcessedStack &aStack)
|
|||
|
||||
Telemetry::ProcessedStack::Module module = {
|
||||
NS_ConvertUTF8toUTF16(moduleName.c_str()),
|
||||
breakpadId
|
||||
nsCString(breakpadId.c_str(), breakpadId.size()),
|
||||
};
|
||||
stack.AddModule(module);
|
||||
}
|
||||
|
|
|
@ -1514,7 +1514,7 @@ AddSharedLibraryInfoToStream(JSONWriter& aWriter, const SharedLibrary& aLib)
|
|||
aWriter.StringProperty("path", NS_ConvertUTF16toUTF8(aLib.GetModulePath()).get());
|
||||
aWriter.StringProperty("debugName", NS_ConvertUTF16toUTF8(aLib.GetDebugName()).get());
|
||||
aWriter.StringProperty("debugPath", NS_ConvertUTF16toUTF8(aLib.GetDebugPath()).get());
|
||||
aWriter.StringProperty("breakpadId", aLib.GetBreakpadId().c_str());
|
||||
aWriter.StringProperty("breakpadId", aLib.GetBreakpadId().get());
|
||||
aWriter.StringProperty("arch", aLib.GetArch().c_str());
|
||||
aWriter.EndObject();
|
||||
}
|
||||
|
|
|
@ -63,11 +63,24 @@ outputMapperLog(const char* aBuf)
|
|||
}
|
||||
#endif
|
||||
|
||||
// Get the breakpad Id for the binary file pointed by bin_name
|
||||
static std::string getId(const char *bin_name)
|
||||
static nsCString
|
||||
IDtoUUIDString(const google_breakpad::wasteful_vector<uint8_t>& aIdentifier)
|
||||
{
|
||||
using namespace google_breakpad;
|
||||
|
||||
nsCString uuid;
|
||||
const std::string str = FileID::ConvertIdentifierToUUIDString(aIdentifier);
|
||||
uuid.Append(str.c_str(), str.size());
|
||||
// This is '0', not '\0', since it represents the breakpad id age.
|
||||
uuid.Append('0');
|
||||
return uuid;
|
||||
}
|
||||
|
||||
// Get the breakpad Id for the binary file pointed by bin_name
|
||||
static nsCString
|
||||
getId(const char *bin_name)
|
||||
{
|
||||
using namespace google_breakpad;
|
||||
using namespace std;
|
||||
|
||||
PageAllocator allocator;
|
||||
auto_wasteful_vector<uint8_t, sizeof(MDGUID)> identifier(&allocator);
|
||||
|
@ -79,7 +92,7 @@ static std::string getId(const char *bin_name)
|
|||
size_t size = 0;
|
||||
if (mapper.Map(&image, &size, bin_name) && image && size) {
|
||||
if (FileID::ElfFileIdentifierFromMappedFile(image, identifier)) {
|
||||
return FileID::ConvertIdentifierToUUIDString(identifier) + "0";
|
||||
return IDtoUUIDString(identifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,10 +100,10 @@ static std::string getId(const char *bin_name)
|
|||
|
||||
FileID file_id(bin_name);
|
||||
if (file_id.ElfFileIdentifier(identifier)) {
|
||||
return FileID::ConvertIdentifierToUUIDString(identifier) + "0";
|
||||
return IDtoUUIDString(identifier);
|
||||
}
|
||||
|
||||
return "";
|
||||
return EmptyCString();
|
||||
}
|
||||
|
||||
static SharedLibrary
|
||||
|
|
|
@ -129,14 +129,17 @@ void addSharedLibrary(const platform_mach_header* header, const char *path, Shar
|
|||
(reinterpret_cast<const char *>(cmd) + cmd->cmdsize);
|
||||
}
|
||||
|
||||
std::stringstream uuid;
|
||||
uuid << std::hex << std::uppercase;
|
||||
nsAutoCString uuid;
|
||||
if (uuid_bytes != nullptr) {
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
uuid << ((uuid_bytes[i] & 0xf0) >> 4);
|
||||
uuid << (uuid_bytes[i] & 0xf);
|
||||
}
|
||||
uuid << '0';
|
||||
uuid.AppendPrintf("%02X" "%02X" "%02X" "%02X"
|
||||
"%02X" "%02X" "%02X" "%02X"
|
||||
"%02X" "%02X" "%02X" "%02X"
|
||||
"%02X" "%02X" "%02X" "%02X"
|
||||
"0" /* breakpad id age */,
|
||||
uuid_bytes[0], uuid_bytes[1], uuid_bytes[2], uuid_bytes[3],
|
||||
uuid_bytes[4], uuid_bytes[5], uuid_bytes[6], uuid_bytes[7],
|
||||
uuid_bytes[8], uuid_bytes[9], uuid_bytes[10], uuid_bytes[11],
|
||||
uuid_bytes[12], uuid_bytes[13], uuid_bytes[14], uuid_bytes[15]);
|
||||
}
|
||||
|
||||
nsAutoString pathStr;
|
||||
|
@ -151,7 +154,7 @@ void addSharedLibrary(const platform_mach_header* header, const char *path, Shar
|
|||
const NXArchInfo* archInfo =
|
||||
NXGetArchInfoFromCpuType(header->cputype, header->cpusubtype);
|
||||
|
||||
info.AddSharedLibrary(SharedLibrary(start, start + size, 0, uuid.str(),
|
||||
info.AddSharedLibrary(SharedLibrary(start, start + size, 0, uuid,
|
||||
nameStr, pathStr, nameStr, pathStr,
|
||||
EmptyCString(),
|
||||
archInfo ? archInfo->name : ""));
|
||||
|
|
|
@ -135,12 +135,9 @@ SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf()
|
|||
}
|
||||
|
||||
for (unsigned int i = 0; i < modulesNum; i++) {
|
||||
nsID pdbSig;
|
||||
uint32_t pdbAge;
|
||||
nsAutoString pdbPathStr;
|
||||
nsAutoString pdbNameStr;
|
||||
char *pdbName = NULL;
|
||||
std::string breakpadId;
|
||||
WCHAR modulePath[MAX_PATH + 1];
|
||||
|
||||
if (!GetModuleFileNameEx(hProcess, hMods[i], modulePath, sizeof(modulePath) / sizeof(WCHAR))) {
|
||||
|
@ -152,6 +149,7 @@ SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf()
|
|||
continue;
|
||||
}
|
||||
|
||||
nsCString breakpadId;
|
||||
// Load the module again to make sure that its handle will remain
|
||||
// valid as we attempt to read the PDB information from it. We load the
|
||||
// DLL as a datafile so that if the module actually gets unloaded between
|
||||
|
@ -165,18 +163,22 @@ SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf()
|
|||
// proceed to actually access those pages.
|
||||
HMODULE handleLock = LoadLibraryEx(modulePath, NULL, LOAD_LIBRARY_AS_DATAFILE);
|
||||
MEMORY_BASIC_INFORMATION vmemInfo = { 0 };
|
||||
nsID pdbSig;
|
||||
uint32_t pdbAge;
|
||||
if (handleLock &&
|
||||
sizeof(vmemInfo) == VirtualQuery(module.lpBaseOfDll, &vmemInfo, sizeof(vmemInfo)) &&
|
||||
vmemInfo.State == MEM_COMMIT &&
|
||||
GetPdbInfo((uintptr_t)module.lpBaseOfDll, pdbSig, pdbAge, &pdbName)) {
|
||||
std::ostringstream stream;
|
||||
stream << pdbSig.ToString() << std::hex << pdbAge;
|
||||
breakpadId = stream.str();
|
||||
std::string::iterator end =
|
||||
std::remove_if(breakpadId.begin(), breakpadId.end(), IsDashOrBraces);
|
||||
breakpadId.erase(end, breakpadId.end());
|
||||
std::transform(breakpadId.begin(), breakpadId.end(),
|
||||
breakpadId.begin(), toupper);
|
||||
MOZ_ASSERT(breakpadId.IsEmpty());
|
||||
breakpadId.AppendPrintf("%08X" // m0
|
||||
"%04X%04X" // m1,m2
|
||||
"%02X%02X%02X%02X%02X%02X%02X%02X" // m3
|
||||
"%X", // pdbAge
|
||||
pdbSig.m0,
|
||||
pdbSig.m1, pdbSig.m2,
|
||||
pdbSig.m3[0], pdbSig.m3[1], pdbSig.m3[2], pdbSig.m3[3],
|
||||
pdbSig.m3[4], pdbSig.m3[5], pdbSig.m3[6], pdbSig.m3[7],
|
||||
pdbAge);
|
||||
|
||||
pdbPathStr = NS_ConvertUTF8toUTF16(pdbName);
|
||||
pdbNameStr = pdbPathStr;
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
SharedLibrary(uintptr_t aStart,
|
||||
uintptr_t aEnd,
|
||||
uintptr_t aOffset,
|
||||
const std::string& aBreakpadId,
|
||||
const nsCString& aBreakpadId,
|
||||
const nsString& aModuleName,
|
||||
const nsString& aModulePath,
|
||||
const nsString& aDebugName,
|
||||
|
@ -93,7 +93,7 @@ public:
|
|||
uintptr_t GetStart() const { return mStart; }
|
||||
uintptr_t GetEnd() const { return mEnd; }
|
||||
uintptr_t GetOffset() const { return mOffset; }
|
||||
const std::string &GetBreakpadId() const { return mBreakpadId; }
|
||||
const nsCString &GetBreakpadId() const { return mBreakpadId; }
|
||||
const nsString &GetModuleName() const { return mModuleName; }
|
||||
const nsString &GetModulePath() const { return mModulePath; }
|
||||
const std::string GetNativeDebugPath() const {
|
||||
|
@ -114,7 +114,7 @@ private:
|
|||
uintptr_t mStart;
|
||||
uintptr_t mEnd;
|
||||
uintptr_t mOffset;
|
||||
std::string mBreakpadId;
|
||||
nsCString mBreakpadId;
|
||||
nsString mModuleName;
|
||||
nsString mModulePath;
|
||||
nsString mDebugName;
|
||||
|
|
|
@ -173,7 +173,7 @@ LateWriteObserver::Observe(IOInterposeObserver::Observation& aOb)
|
|||
sha1Stream.Printf("%u\n", (unsigned)numModules);
|
||||
for (size_t i = 0; i < numModules; ++i) {
|
||||
Telemetry::ProcessedStack::Module module = stack.GetModule(i);
|
||||
sha1Stream.Printf("%s %s\n", module.mBreakpadId.c_str(),
|
||||
sha1Stream.Printf("%s %s\n", module.mBreakpadId.get(),
|
||||
NS_ConvertUTF16toUTF8(module.mName).get());
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче