Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Introducing RawHex, a counterpart to RawPointer
https://bugs.webkit.org/show_bug.cgi?id=241743 Reviewed by Saam Barati. RawHex is for dumping integral values in hex just like RawPointer is for dumping pointers. And similarly, RawHex is meant to be used with PrintStream. For example: dataLog(RawHex(42)); // prints 0x2a dataLog(RawHex(0x42); // prints 0x42 dataLog(RawHex(256)); // prints 0x100 dataLog(RawHex(65536); // prints 0x10000 dataLog(RawHex(4294967295); // prints 0xffffffff dataLog(RawHex(4294967296); // prints 0x100000000 dataLog(RawHex(INT8_MIN); // prints 0x80 dataLog(RawHex(INT16_MIN); // prints 0x8000 dataLog(RawHex(INT32_MIN); // prints 0x80000000 dataLog(RawHex(-1); // prints 0xffffffff dataLog(RawHex(INT64_MIN); // prints 0x8000000000000000 dataLog(RawHex(INT64_MAX); // prints 0x7fffffffffffffff dataLog(RawHex(UINT64_MAX); // prints 0xffffffffffffffff Also fixed up places where we were casting integral values into pointers, and then using RawPointer to dump them in hex. * Source/JavaScriptCore/bytecode/BytecodeDumper.cpp: (JSC::Wasm::BytecodeDumper::formatConstant const): * Source/JavaScriptCore/interpreter/StackVisitor.cpp: (JSC::StackVisitor::Frame::dump const): * Source/JavaScriptCore/runtime/ExecutableBase.cpp: (JSC::ExecutableBase::dump const): * Source/JavaScriptCore/runtime/LazyPropertyInlines.h: (JSC::ElementType>::dump const): * Source/JavaScriptCore/runtime/SamplingProfiler.cpp: (JSC::SamplingProfiler::reportTopBytecodes): * Source/JavaScriptCore/tools/Integrity.cpp: (JSC::Integrity::Random::reloadAndCheckShouldAuditSlow): * Source/JavaScriptCore/wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseBody): * Source/JavaScriptCore/wasm/WasmOpcodeOrigin.cpp: (JSC::Wasm::OpcodeOrigin::dump const): * Source/WTF/WTF.xcodeproj/project.pbxproj: * Source/WTF/wtf/CMakeLists.txt: * Source/WTF/wtf/PrintStream.cpp: (WTF::printInternal): * Source/WTF/wtf/PrintStream.h: * Source/WTF/wtf/RawHex.h: Added. (WTF::RawHex::RawHex): (WTF::RawHex::ptr const): (WTF::RawHex::is64Bit const): (WTF::RawHex::u64 const): Canonical link: https://commits.webkit.org/251665@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295660 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
13 changed files
with
145 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -218,6 +218,7 @@ set(WTF_PUBLIC_HEADERS | ||
RandomNumberSeed.h | ||
Range.h | ||
RangeSet.h | ||
RawHex.h | ||
RawPointer.h | ||
RawPtrTraits.h | ||
RawValueTraits.h | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright (C) 2022 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
namespace WTF { | ||
|
||
// For printing integral values in hex. | ||
// See also the printInternal function for RaswHex in PrintStream.cpp. | ||
|
||
class RawHex { | ||
public: | ||
RawHex() = default; | ||
|
||
explicit RawHex(int8_t value) | ||
: RawHex(static_cast<uint8_t>(value)) | ||
{ } | ||
explicit RawHex(uint8_t value) | ||
: RawHex(static_cast<uintptr_t>(value)) | ||
{ } | ||
|
||
explicit RawHex(int16_t value) | ||
: RawHex(static_cast<uint16_t>(value)) | ||
{ } | ||
explicit RawHex(uint16_t value) | ||
: RawHex(static_cast<uintptr_t>(value)) | ||
{ } | ||
|
||
#if CPU(ADDRESS64) || OS(DARWIN) | ||
// These causes build errors for CPU(ADDRESS32) on some ports because int32_t | ||
// is already handled by intptr_t, and uint32_t is handled by uintptr_t. | ||
explicit RawHex(int32_t value) | ||
: RawHex(static_cast<uint32_t>(value)) | ||
{ } | ||
explicit RawHex(uint32_t value) | ||
: RawHex(static_cast<uintptr_t>(value)) | ||
{ } | ||
#endif | ||
|
||
#if CPU(ADDRESS32) || OS(DARWIN) | ||
// These causes build errors for CPU(ADDRESS64) on some ports because int64_t | ||
// is already handled by intptr_t, and uint64_t is handled by uintptr_t. | ||
explicit RawHex(int64_t value) | ||
: RawHex(static_cast<uint64_t>(value)) | ||
{ } | ||
#if CPU(ADDRESS64) // on OS(DARWIN) | ||
explicit RawHex(uint64_t value) | ||
: RawHex(static_cast<uintptr_t>(value)) | ||
{ } | ||
#else | ||
explicit RawHex(uint64_t value) | ||
: m_is64Bit(true) | ||
, m_u64(value) | ||
{ } | ||
#endif | ||
#endif // CPU(ADDRESS64) | ||
|
||
explicit RawHex(intptr_t value) | ||
: RawHex(static_cast<uintptr_t>(value)) | ||
{ } | ||
explicit RawHex(uintptr_t value) | ||
: m_ptr(reinterpret_cast<void*>(value)) | ||
{ } | ||
|
||
const void* ptr() const { return m_ptr; } | ||
|
||
#if !CPU(ADDRESS64) | ||
bool is64Bit() const { return m_is64Bit; } | ||
uint64_t u64() const { return m_u64; } | ||
#endif | ||
|
||
private: | ||
#if !CPU(ADDRESS64) | ||
bool m_is64Bit { false }; | ||
#endif | ||
union { | ||
const void* m_ptr { nullptr }; | ||
#if !CPU(ADDRESS64) | ||
uint64_t m_u64; | ||
#endif | ||
}; | ||
}; | ||
|
||
} // namespace WTF | ||
|
||
using WTF::RawHex; |