Fix printf formats

The usage of __attribute__((format(x, y)) was either wrong or missing from multiple functions, leading to erroneous formats. This CL:

 - Imports PRINTF_FORMAT macro from Chrome's src/base/compiler-specific.h.
 - Uses it appropriately.
 - Imports Chrome's base/format_macros.h mainly to fix size_t formats (further cleanup could be done).
 - Fixes a bunch of incorrect formats.

Original CL: https://codereview.chromium.org/1869433004
Reverted in: https://codereview.chromium.org/1867383002

R= jochen@chromium.org
TBR= bmeurer@chromium.org, yangguo@chromium.org, ahaas@chromium.org

Review URL: https://codereview.chromium.org/1877453002

Cr-Commit-Position: refs/heads/master@{#35394}
This commit is contained in:
jfb 2016-04-11 09:25:56 -07:00 committed by Commit bot
parent 39d121d1e3
commit bf50532928
40 changed files with 350 additions and 261 deletions

View File

@ -1798,6 +1798,7 @@ source_set("v8_libbase") {
"src/base/division-by-constant.cc",
"src/base/division-by-constant.h",
"src/base/flags.h",
"src/base/format-macros.h",
"src/base/functional.cc",
"src/base/functional.h",
"src/base/iterator.h",

View File

@ -14,6 +14,7 @@
#include "src/arm64/disasm-arm64.h"
#include "src/arm64/instrument-arm64.h"
#include "src/assembler.h"
#include "src/base/compiler-specific.h"
#include "src/globals.h"
#include "src/utils.h"
@ -794,7 +795,7 @@ class Simulator : public DecoderVisitor {
// Output stream.
FILE* stream_;
PrintDisassembler* print_disasm_;
void PRINTF_METHOD_CHECKING TraceSim(const char* format, ...);
void PRINTF_FORMAT(2, 3) TraceSim(const char* format, ...);
// Instrumentation.
Instrument* instrument_;

View File

@ -1055,7 +1055,8 @@ void PrettyPrinter::PrintLiteral(Handle<Object> value, bool quote) {
if (object->IsJSFunction()) {
Print("JS-Function");
} else if (object->IsJSArray()) {
Print("JS-array[%u]", JSArray::cast(object)->length());
Print("JS-array[%u]",
Smi::cast(JSArray::cast(object)->length())->value());
} else if (object->IsJSObject()) {
Print("JS-Object");
} else {
@ -1145,7 +1146,7 @@ void AstPrinter::PrintIndented(const char* txt) {
for (int i = 0; i < indent_; i++) {
Print(". ");
}
Print(txt);
Print("%s", txt);
}
@ -1522,7 +1523,7 @@ void AstPrinter::VisitRegExpLiteral(RegExpLiteral* node) {
if (node->flags() & RegExp::kSticky) buf[i++] = 'y';
buf[i] = '\0';
PrintIndented("FLAGS ");
Print(buf.start());
Print("%s", buf.start());
Print("\n");
}

View File

@ -7,6 +7,7 @@
#include "src/allocation.h"
#include "src/ast/ast.h"
#include "src/base/compiler-specific.h"
namespace v8 {
namespace internal {
@ -20,7 +21,7 @@ class CallPrinter : public AstVisitor {
// string. The result string is alive as long as the CallPrinter is alive.
const char* Print(FunctionLiteral* program, int position);
void Print(const char* format, ...);
void PRINTF_FORMAT(2, 3) Print(const char* format, ...);
void Find(AstNode* node, bool print = false);
@ -62,7 +63,7 @@ class PrettyPrinter: public AstVisitor {
const char* PrintExpression(FunctionLiteral* program);
const char* PrintProgram(FunctionLiteral* program);
void Print(const char* format, ...);
void PRINTF_FORMAT(2, 3) Print(const char* format, ...);
// Print a node to stdout.
static void PrintOut(Isolate* isolate, AstNode* node);

View File

@ -26,6 +26,17 @@
#define WARN_UNUSED_RESULT /* NOT SUPPORTED */
#endif
// Tell the compiler a function is using a printf-style format string.
// |format_param| is the one-based index of the format string parameter;
// |dots_param| is the one-based index of the "..." parameter.
// For v*printf functions (which take a va_list), pass 0 for dots_param.
// (This is undocumented but matches what the system C headers do.)
#if defined(__GNUC__)
#define PRINTF_FORMAT(format_param, dots_param) \
__attribute__((format(printf, format_param, dots_param)))
#else
#define PRINTF_FORMAT(format_param, dots_param)
#endif
// The C++ standard requires that static const members have an out-of-class
// definition (in a single compilation unit), but MSVC chokes on this (when

97
src/base/format-macros.h Normal file
View File

@ -0,0 +1,97 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_FORMAT_MACROS_H_
#define BASE_FORMAT_MACROS_H_
// This file defines the format macros for some integer types.
// To print a 64-bit value in a portable way:
// int64_t value;
// printf("xyz:%" PRId64, value);
// The "d" in the macro corresponds to %d; you can also use PRIu64 etc.
//
// For wide strings, prepend "Wide" to the macro:
// int64_t value;
// StringPrintf(L"xyz: %" WidePRId64, value);
//
// To print a size_t value in a portable way:
// size_t size;
// printf("xyz: %" PRIuS, size);
// The "u" in the macro corresponds to %u, and S is for "size".
#include <stddef.h>
#include <stdint.h>
#include "src/base/build_config.h"
#if defined(V8_OS_POSIX) && (defined(_INTTYPES_H) || defined(_INTTYPES_H_)) && \
!defined(PRId64)
#error "inttypes.h has already been included before this header file, but "
#error "without __STDC_FORMAT_MACROS defined."
#endif
#if defined(V8_OS_POSIX) && !defined(__STDC_FORMAT_MACROS)
#define __STDC_FORMAT_MACROS
#endif
#include <inttypes.h>
#if defined(V8_OS_POSIX)
// GCC will concatenate wide and narrow strings correctly, so nothing needs to
// be done here.
#define WidePRId64 PRId64
#define WidePRIu64 PRIu64
#define WidePRIx64 PRIx64
#if !defined(PRIuS)
#define PRIuS "zu"
#endif
// The size of NSInteger and NSUInteger varies between 32-bit and 64-bit
// architectures and Apple does not provides standard format macros and
// recommends casting. This has many drawbacks, so instead define macros
// for formatting those types.
#if defined(V8_OS_MACOSX)
#if defined(V8_HOST_ARCH_64_BIT)
#if !defined(PRIdNS)
#define PRIdNS "ld"
#endif
#if !defined(PRIuNS)
#define PRIuNS "lu"
#endif
#if !defined(PRIxNS)
#define PRIxNS "lx"
#endif
#else // defined(V8_HOST_ARCH_64_BIT)
#if !defined(PRIdNS)
#define PRIdNS "d"
#endif
#if !defined(PRIuNS)
#define PRIuNS "u"
#endif
#if !defined(PRIxNS)
#define PRIxNS "x"
#endif
#endif
#endif // defined(V8_OS_MACOSX)
#else // V8_OS_WIN
#if !defined(PRId64) || !defined(PRIu64) || !defined(PRIx64)
#error "inttypes.h provided by win toolchain should define these."
#endif
#define WidePRId64 L"I64d"
#define WidePRIu64 L"I64u"
#define WidePRIx64 L"I64x"
#if !defined(PRIuS)
#define PRIuS "Iu"
#endif
#endif
#endif // BASE_FORMAT_MACROS_H_

View File

@ -10,9 +10,10 @@
#include <string>
#include "src/base/build_config.h"
#include "src/base/compiler-specific.h"
extern "C" V8_NORETURN void V8_Fatal(const char* file, int line,
const char* format, ...);
extern "C" PRINTF_FORMAT(3, 4) V8_NORETURN
void V8_Fatal(const char* file, int line, const char* format, ...);
extern "C" void V8_RuntimeError(const char* file, int line,
const char* message);

View File

@ -5,13 +5,8 @@
#ifndef V8_BASE_MACROS_H_
#define V8_BASE_MACROS_H_
#include <stddef.h>
#include <stdint.h>
#include <cstring>
#include "src/base/build_config.h"
#include "src/base/compiler-specific.h"
#include "src/base/format-macros.h"
#include "src/base/logging.h"
@ -274,23 +269,27 @@ inline void USE(T) { }
#define V8PRIdPTR V8_PTR_PREFIX "d"
#define V8PRIuPTR V8_PTR_PREFIX "u"
// ptrdiff_t is 't' according to the standard, but MSVC uses 'I'.
#if V8_CC_MSVC
#define V8PRIxPTRDIFF "Ix"
#define V8PRIdPTRDIFF "Id"
#define V8PRIuPTRDIFF "Iu"
#else
#define V8PRIxPTRDIFF "tx"
#define V8PRIdPTRDIFF "td"
#define V8PRIuPTRDIFF "tu"
#endif
// Fix for Mac OS X defining uintptr_t as "unsigned long":
#if V8_OS_MACOSX
#undef V8PRIxPTR
#define V8PRIxPTR "lx"
#undef V8PRIdPTR
#define V8PRIdPTR "ld"
#undef V8PRIuPTR
#define V8PRIuPTR "lxu"
#endif
// GCC on S390 31-bit expands 'size_t' to 'long unsigned int'
// instead of 'int', resulting in compilation errors with %d.
// The printf format specifier needs to be %zd instead.
#if V8_HOST_ARCH_S390 && !V8_HOST_ARCH_64_BIT
#define V8_SIZET_PREFIX "z"
#else
#define V8_SIZET_PREFIX ""
#endif
// The following macro works on both 32 and 64-bit platforms.
// Usage: instead of writing 0x1234567890123456
// write V8_2PART_UINT64_C(0x12345678,90123456);

View File

@ -26,6 +26,7 @@
#include <vector>
#include "src/base/build_config.h"
#include "src/base/compiler-specific.h"
#include "src/base/platform/mutex.h"
#include "src/base/platform/semaphore.h"
@ -154,18 +155,19 @@ class OS {
// Print output to console. This is mostly used for debugging output.
// On platforms that has standard terminal output, the output
// should go to stdout.
static void Print(const char* format, ...);
static void VPrint(const char* format, va_list args);
static PRINTF_FORMAT(1, 2) void Print(const char* format, ...);
static PRINTF_FORMAT(1, 0) void VPrint(const char* format, va_list args);
// Print output to a file. This is mostly used for debugging output.
static void FPrint(FILE* out, const char* format, ...);
static void VFPrint(FILE* out, const char* format, va_list args);
static PRINTF_FORMAT(2, 3) void FPrint(FILE* out, const char* format, ...);
static PRINTF_FORMAT(2, 0) void VFPrint(FILE* out, const char* format,
va_list args);
// Print error output to console. This is mostly used for error message
// output. On platforms that has standard terminal output, the output
// should go to stderr.
static void PrintError(const char* format, ...);
static void VPrintError(const char* format, va_list args);
static PRINTF_FORMAT(1, 2) void PrintError(const char* format, ...);
static PRINTF_FORMAT(1, 0) void VPrintError(const char* format, va_list args);
// Allocate/Free memory used by JS heap. Pages are readable/writable, but
// they are not guaranteed to be executable unless 'executable' is true.
@ -222,11 +224,10 @@ class OS {
// Safe formatting print. Ensures that str is always null-terminated.
// Returns the number of chars written, or -1 if output was truncated.
static int SNPrintF(char* str, int length, const char* format, ...);
static int VSNPrintF(char* str,
int length,
const char* format,
va_list args);
static PRINTF_FORMAT(3, 4) int SNPrintF(char* str, int length,
const char* format, ...);
static PRINTF_FORMAT(3, 0) int VSNPrintF(char* str, int length,
const char* format, va_list args);
static char* StrChr(char* str, int c);
static void StrNCpy(char* dest, int length, const char* src, size_t n);

View File

@ -66,9 +66,8 @@ static void WriteLine(std::ostream& os, const char* name,
double size_percent =
static_cast<double>(stats.total_allocated_bytes_ * 100) /
static_cast<double>(total_stats.total_allocated_bytes_);
base::OS::SNPrintF(buffer, kBufferSize,
"%28s %10.3f (%5.1f%%) "
"%10u (%5.1f%%) %10u %10u",
base::OS::SNPrintF(buffer, kBufferSize, "%28s %10.3f (%5.1f%%) %10" PRIuS
" (%5.1f%%) %10" PRIuS " %10" PRIuS,
name, ms, percent, stats.total_allocated_bytes_,
size_percent, stats.max_allocated_bytes_,
stats.absolute_max_allocated_bytes_);

View File

@ -5,6 +5,7 @@
#ifndef V8_CRANKSHAFT_HYDROGEN_RANGE_ANALYSIS_H_
#define V8_CRANKSHAFT_HYDROGEN_RANGE_ANALYSIS_H_
#include "src/base/compiler-specific.h"
#include "src/crankshaft/hydrogen.h"
namespace v8 {
@ -21,7 +22,7 @@ class HRangeAnalysisPhase : public HPhase {
void Run();
private:
void TraceRange(const char* msg, ...);
PRINTF_FORMAT(2, 3) void TraceRange(const char* msg, ...);
void InferControlFlowRange(HCompareNumericAndBranch* test,
HBasicBlock* dest);
void UpdateControlFlowRange(Token::Value op, HValue* value, HValue* other);

View File

@ -6,6 +6,7 @@
#define V8_CRANKSHAFT_LITHIUM_ALLOCATOR_H_
#include "src/allocation.h"
#include "src/base/compiler-specific.h"
#include "src/crankshaft/compilation-phase.h"
#include "src/crankshaft/lithium.h"
#include "src/zone.h"
@ -327,7 +328,7 @@ class LAllocator BASE_EMBEDDED {
public:
LAllocator(int first_virtual_register, HGraph* graph);
static void TraceAlloc(const char* msg, ...);
static PRINTF_FORMAT(1, 2) void TraceAlloc(const char* msg, ...);
// Checks whether the value of a given virtual register is tagged.
bool HasTaggedValue(int virtual_register) const;

View File

@ -35,7 +35,7 @@ class LCodeGenBase BASE_EMBEDDED {
LPlatformChunk* chunk() const { return chunk_; }
HGraph* graph() const;
void FPRINTF_CHECKING Comment(const char* format, ...);
void PRINTF_FORMAT(2, 3) Comment(const char* format, ...);
void DeoptComment(const Deoptimizer::DeoptInfo& deopt_info);
static Deoptimizer::DeoptInfo MakeDeoptInfo(
LInstruction* instr, Deoptimizer::DeoptReason deopt_reason);

View File

@ -109,10 +109,9 @@ static int DecodeIt(Isolate* isolate, std::ostream* os,
it->rinfo()->rmode() == RelocInfo::INTERNAL_REFERENCE) {
// raw pointer embedded in code stream, e.g., jump table
byte* ptr = *reinterpret_cast<byte**>(pc);
SNPrintF(decode_buffer,
"%08" V8PRIxPTR " jump table entry %4" V8PRIdPTR,
reinterpret_cast<intptr_t>(ptr),
ptr - begin);
SNPrintF(
decode_buffer, "%08" V8PRIxPTR " jump table entry %4" PRIuS,
reinterpret_cast<intptr_t>(ptr), static_cast<size_t>(ptr - begin));
pc += sizeof(ptr);
} else {
decode_buffer[0] = '\0';
@ -147,7 +146,7 @@ static int DecodeIt(Isolate* isolate, std::ostream* os,
}
// Instruction address and instruction offset.
out.AddFormatted("%p %4d ", prev_pc, prev_pc - begin);
out.AddFormatted("%p %4" V8PRIdPTRDIFF " ", prev_pc, prev_pc - begin);
// Instruction.
out.AddFormatted("%s", decode_buffer.start());
@ -171,9 +170,11 @@ static int DecodeIt(Isolate* isolate, std::ostream* os,
RelocInfo::Mode rmode = relocinfo.rmode();
if (RelocInfo::IsPosition(rmode)) {
if (RelocInfo::IsStatementPosition(rmode)) {
out.AddFormatted(" ;; debug: statement %d", relocinfo.data());
out.AddFormatted(" ;; debug: statement %" V8PRIdPTR,
relocinfo.data());
} else {
out.AddFormatted(" ;; debug: position %d", relocinfo.data());
out.AddFormatted(" ;; debug: position %" V8PRIdPTR,
relocinfo.data());
}
} else if (rmode == RelocInfo::DEOPT_REASON) {
Deoptimizer::DeoptReason reason =

View File

@ -888,7 +888,7 @@ void ObjectGroupsTracer::PrintInternalFields(JSObject* js_object) {
}
void ObjectGroupsTracer::PrintObjectGroup(ObjectGroup* group) {
PrintIsolate(isolate_, "ObjectGroup (size: %lu)\n", group->length);
PrintIsolate(isolate_, "ObjectGroup (size: %" PRIuS ")\n", group->length);
Object*** objects = group->objects;
for (size_t i = 0; i < group->length; ++i) {
@ -898,7 +898,7 @@ void ObjectGroupsTracer::PrintObjectGroup(ObjectGroup* group) {
}
void ObjectGroupsTracer::PrintImplicitRefGroup(ImplicitRefGroup* group) {
PrintIsolate(isolate_, "ImplicitRefGroup (children count: %lu)\n",
PrintIsolate(isolate_, "ImplicitRefGroup (children count: %" PRIuS ")\n",
group->length);
PrintIsolate(isolate_, " - Parent: ");
PrintObject(*(group->parent));
@ -1223,8 +1223,7 @@ void GlobalHandles::PrintStats() {
}
PrintF("Global Handle Statistics:\n");
PrintF(" allocated memory = %" V8_SIZET_PREFIX V8_PTR_PREFIX "dB\n",
total * sizeof(Node));
PrintF(" allocated memory = %" PRIuS "B\n", total * sizeof(Node));
PrintF(" # weak = %d\n", weak);
PrintF(" # pending = %d\n", pending);
PrintF(" # near_death = %d\n", near_death);

View File

@ -41,8 +41,7 @@ void GCIdleTimeAction::Print() {
void GCIdleTimeHeapState::Print() {
PrintF("contexts_disposed=%d ", contexts_disposed);
PrintF("contexts_disposal_rate=%f ", contexts_disposal_rate);
PrintF("size_of_objects=%" V8_SIZET_PREFIX V8_PTR_PREFIX "d ",
size_of_objects);
PrintF("size_of_objects=%" PRIuS " ", size_of_objects);
PrintF("incremental_marking_stopped=%d ", incremental_marking_stopped);
}

View File

@ -411,7 +411,7 @@ void GCTracer::Output(const char* format, ...) const {
void GCTracer::Print() const {
if (FLAG_trace_gc) {
PrintIsolate(heap_->isolate(), "");
PrintIsolate(heap_->isolate(), "%s", "");
}
Output("%8.0f ms: ", heap_->isolate()->time_millis_since_init());
@ -480,20 +480,20 @@ void GCTracer::PrintNVP() const {
"steps_count=%d "
"steps_took=%.1f "
"scavenge_throughput=%.f "
"total_size_before=%" V8_PTR_PREFIX
"d "
"total_size_after=%" V8_PTR_PREFIX
"d "
"holes_size_before=%" V8_PTR_PREFIX
"d "
"holes_size_after=%" V8_PTR_PREFIX
"d "
"allocated=%" V8_PTR_PREFIX
"d "
"promoted=%" V8_PTR_PREFIX
"d "
"semi_space_copied=%" V8_PTR_PREFIX
"d "
"total_size_before=%" V8PRIdPTR
" "
"total_size_after=%" V8PRIdPTR
" "
"holes_size_before=%" V8PRIdPTR
" "
"holes_size_after=%" V8PRIdPTR
" "
"allocated=%" V8PRIdPTR
" "
"promoted=%" V8PRIdPTR
" "
"semi_space_copied=%" V8PRIdPTR
" "
"nodes_died_in_new=%d "
"nodes_copied_in_new=%d "
"nodes_promoted=%d "
@ -586,20 +586,20 @@ void GCTracer::PrintNVP() const {
"finalization_steps_took=%.1f "
"finalization_longest_step=%.1f "
"incremental_marking_throughput=%.f "
"total_size_before=%" V8_PTR_PREFIX
"d "
"total_size_after=%" V8_PTR_PREFIX
"d "
"holes_size_before=%" V8_PTR_PREFIX
"d "
"holes_size_after=%" V8_PTR_PREFIX
"d "
"allocated=%" V8_PTR_PREFIX
"d "
"promoted=%" V8_PTR_PREFIX
"d "
"semi_space_copied=%" V8_PTR_PREFIX
"d "
"total_size_before=%" V8PRIdPTR
" "
"total_size_after=%" V8PRIdPTR
" "
"holes_size_before=%" V8PRIdPTR
" "
"holes_size_after=%" V8PRIdPTR
" "
"allocated=%" V8PRIdPTR
" "
"promoted=%" V8PRIdPTR
" "
"semi_space_copied=%" V8PRIdPTR
" "
"nodes_died_in_new=%d "
"nodes_copied_in_new=%d "
"nodes_promoted=%d "

View File

@ -5,6 +5,7 @@
#ifndef V8_HEAP_GC_TRACER_H_
#define V8_HEAP_GC_TRACER_H_
#include "src/base/compiler-specific.h"
#include "src/base/platform/platform.h"
#include "src/counters.h"
#include "src/globals.h"
@ -383,7 +384,7 @@ class GCTracer {
// Prints a line and also adds it to the heap's ring buffer so that
// it can be included in later crash dumps.
void Output(const char* format, ...) const;
void PRINTF_FORMAT(2, 3) Output(const char* format, ...) const;
void ClearMarkCompactStatistics() {
cumulative_incremental_marking_steps_ = 0;

View File

@ -343,61 +343,59 @@ void Heap::ReportStatisticsBeforeGC() {
void Heap::PrintShortHeapStatistics() {
if (!FLAG_trace_gc_verbose) return;
PrintIsolate(isolate_, "Memory allocator, used: %6" V8_PTR_PREFIX
"d KB"
", available: %6" V8_PTR_PREFIX "d KB\n",
PrintIsolate(isolate_, "Memory allocator, used: %6" V8PRIdPTR
" KB, available: %6" V8PRIdPTR " KB\n",
memory_allocator()->Size() / KB,
memory_allocator()->Available() / KB);
PrintIsolate(isolate_, "New space, used: %6" V8_PTR_PREFIX
"d KB"
", available: %6" V8_PTR_PREFIX
"d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
PrintIsolate(isolate_, "New space, used: %6" V8PRIdPTR
" KB"
", available: %6" V8PRIdPTR
" KB"
", committed: %6" V8PRIdPTR " KB\n",
new_space_.Size() / KB, new_space_.Available() / KB,
new_space_.CommittedMemory() / KB);
PrintIsolate(isolate_, "Old space, used: %6" V8_PTR_PREFIX
"d KB"
", available: %6" V8_PTR_PREFIX
"d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
PrintIsolate(isolate_, "Old space, used: %6" V8PRIdPTR
" KB"
", available: %6" V8PRIdPTR
" KB"
", committed: %6" V8PRIdPTR " KB\n",
old_space_->SizeOfObjects() / KB, old_space_->Available() / KB,
old_space_->CommittedMemory() / KB);
PrintIsolate(isolate_, "Code space, used: %6" V8_PTR_PREFIX
"d KB"
", available: %6" V8_PTR_PREFIX
"d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
PrintIsolate(isolate_, "Code space, used: %6" V8PRIdPTR
" KB"
", available: %6" V8PRIdPTR
" KB"
", committed: %6" V8PRIdPTR " KB\n",
code_space_->SizeOfObjects() / KB, code_space_->Available() / KB,
code_space_->CommittedMemory() / KB);
PrintIsolate(isolate_, "Map space, used: %6" V8_PTR_PREFIX
"d KB"
", available: %6" V8_PTR_PREFIX
"d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
PrintIsolate(isolate_, "Map space, used: %6" V8PRIdPTR
" KB"
", available: %6" V8PRIdPTR
" KB"
", committed: %6" V8PRIdPTR " KB\n",
map_space_->SizeOfObjects() / KB, map_space_->Available() / KB,
map_space_->CommittedMemory() / KB);
PrintIsolate(isolate_, "Large object space, used: %6" V8_PTR_PREFIX
"d KB"
", available: %6" V8_PTR_PREFIX
"d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
PrintIsolate(isolate_, "Large object space, used: %6" V8PRIdPTR
" KB"
", available: %6" V8PRIdPTR
" KB"
", committed: %6" V8PRIdPTR " KB\n",
lo_space_->SizeOfObjects() / KB, lo_space_->Available() / KB,
lo_space_->CommittedMemory() / KB);
PrintIsolate(isolate_, "All spaces, used: %6" V8_PTR_PREFIX
"d KB"
", available: %6" V8_PTR_PREFIX
"d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
PrintIsolate(isolate_, "All spaces, used: %6" V8PRIdPTR
" KB"
", available: %6" V8PRIdPTR
" KB"
", committed: %6" V8PRIdPTR " KB\n",
this->SizeOfObjects() / KB, this->Available() / KB,
this->CommittedMemory() / KB);
PrintIsolate(
isolate_, "External memory reported: %6" V8_PTR_PREFIX "d KB\n",
isolate_, "External memory reported: %6" V8PRIdPTR " KB\n",
static_cast<intptr_t>(amount_of_external_allocated_memory_ / KB));
PrintIsolate(isolate_, "Total time spent in GC : %.1f ms\n",
total_gc_time_ms_);
}
// TODO(1238405): Combine the infrastructure for --heap-stats and
// --log-gc to avoid the complicated preprocessor and flag testing.
void Heap::ReportStatisticsAfterGC() {
@ -4484,7 +4482,7 @@ void Heap::ReportHeapStatistics(const char* title) {
USE(title);
PrintF(">>>>>> =============== %s (%d) =============== >>>>>>\n", title,
gc_count_);
PrintF("old_generation_allocation_limit_ %" V8_PTR_PREFIX "d\n",
PrintF("old_generation_allocation_limit_ %" V8PRIdPTR "\n",
old_generation_allocation_limit_);
PrintF("\n");
@ -5151,8 +5149,8 @@ void Heap::SetOldGenerationAllocationLimit(intptr_t old_gen_size,
CalculateOldGenerationAllocationLimit(factor, old_gen_size);
if (FLAG_trace_gc_verbose) {
PrintIsolate(isolate_, "Grow: old size: %" V8_PTR_PREFIX
"d KB, new limit: %" V8_PTR_PREFIX "d KB (%.1f)\n",
PrintIsolate(isolate_, "Grow: old size: %" V8PRIdPTR
" KB, new limit: %" V8PRIdPTR " KB (%.1f)\n",
old_gen_size / KB, old_generation_allocation_limit_ / KB,
factor);
}
@ -5166,10 +5164,10 @@ void Heap::DampenOldGenerationAllocationLimit(intptr_t old_gen_size,
intptr_t limit = CalculateOldGenerationAllocationLimit(factor, old_gen_size);
if (limit < old_generation_allocation_limit_) {
if (FLAG_trace_gc_verbose) {
PrintIsolate(isolate_, "Dampen: old size: %" V8_PTR_PREFIX
"d KB, old limit: %" V8_PTR_PREFIX
"d KB, "
"new limit: %" V8_PTR_PREFIX "d KB (%.1f)\n",
PrintIsolate(isolate_,
"Dampen: old size: %" V8PRIdPTR " KB, old limit: %" V8PRIdPTR
" KB, "
"new limit: %" V8PRIdPTR " KB (%.1f)\n",
old_gen_size / KB, old_generation_allocation_limit_ / KB,
limit / KB, factor);
}
@ -5394,7 +5392,7 @@ void Heap::TearDown() {
PrintF("max_gc_pause=%.1f ", get_max_gc_pause());
PrintF("total_gc_time=%.1f ", total_gc_time_ms_);
PrintF("min_in_mutator=%.1f ", get_min_in_mutator());
PrintF("max_alive_after_gc=%" V8_PTR_PREFIX "d ", get_max_alive_after_gc());
PrintF("max_alive_after_gc=%" V8PRIdPTR " ", get_max_alive_after_gc());
PrintF("total_marking_time=%.1f ", tracer()->cumulative_marking_duration());
PrintF("total_sweeping_time=%.1f ",
tracer()->cumulative_sweeping_duration());
@ -5403,17 +5401,17 @@ void Heap::TearDown() {
if (FLAG_print_max_heap_committed) {
PrintF("\n");
PrintF("maximum_committed_by_heap=%" V8_PTR_PREFIX "d ",
PrintF("maximum_committed_by_heap=%" V8PRIdPTR " ",
MaximumCommittedMemory());
PrintF("maximum_committed_by_new_space=%" V8_PTR_PREFIX "d ",
PrintF("maximum_committed_by_new_space=%" V8PRIdPTR " ",
new_space_.MaximumCommittedMemory());
PrintF("maximum_committed_by_old_space=%" V8_PTR_PREFIX "d ",
PrintF("maximum_committed_by_old_space=%" V8PRIdPTR " ",
old_space_->MaximumCommittedMemory());
PrintF("maximum_committed_by_code_space=%" V8_PTR_PREFIX "d ",
PrintF("maximum_committed_by_code_space=%" V8PRIdPTR " ",
code_space_->MaximumCommittedMemory());
PrintF("maximum_committed_by_map_space=%" V8_PTR_PREFIX "d ",
PrintF("maximum_committed_by_map_space=%" V8PRIdPTR " ",
map_space_->MaximumCommittedMemory());
PrintF("maximum_committed_by_lo_space=%" V8_PTR_PREFIX "d ",
PrintF("maximum_committed_by_lo_space=%" V8PRIdPTR " ",
lo_space_->MaximumCommittedMemory());
PrintF("\n\n");
}

View File

@ -759,8 +759,8 @@ void MarkCompactCollector::CollectEvacuationCandidates(PagedSpace* space) {
if (FLAG_trace_fragmentation_verbose) {
PrintIsolate(isolate(),
"compaction-selection-page: space=%s free_bytes_page=%d "
"fragmentation_limit_kb=%d fragmentation_limit_percent=%d "
"sum_compaction_kb=%d "
"fragmentation_limit_kb=%" V8PRIdPTR
" fragmentation_limit_percent=%d sum_compaction_kb=%d "
"compaction_limit_kb=%d\n",
AllocationSpaceName(space->identity()), free_bytes / KB,
free_bytes_threshold / KB, target_fragmentation_percent,
@ -3142,16 +3142,15 @@ void MarkCompactCollector::EvacuatePagesInParallel() {
delete[] evacuators;
if (FLAG_trace_evacuation) {
PrintIsolate(
isolate(),
"%8.0f ms: evacuation-summary: parallel=%s pages=%d aborted=%d "
"wanted_tasks=%d tasks=%d cores=%d live_bytes=%" V8_PTR_PREFIX
"d compaction_speed=%.f\n",
isolate()->time_millis_since_init(),
FLAG_parallel_compaction ? "yes" : "no", job.NumberOfPages(),
abandoned_pages, wanted_num_tasks, job.NumberOfTasks(),
V8::GetCurrentPlatform()->NumberOfAvailableBackgroundThreads(),
live_bytes, compaction_speed);
PrintIsolate(isolate(),
"%8.0f ms: evacuation-summary: parallel=%s pages=%d "
"aborted=%d wanted_tasks=%d tasks=%d cores=%" PRIuS
" live_bytes=%" V8PRIdPTR " compaction_speed=%.f\n",
isolate()->time_millis_since_init(),
FLAG_parallel_compaction ? "yes" : "no", job.NumberOfPages(),
abandoned_pages, wanted_num_tasks, job.NumberOfTasks(),
V8::GetCurrentPlatform()->NumberOfAvailableBackgroundThreads(),
live_bytes, compaction_speed);
}
}

View File

@ -882,10 +882,7 @@ void MemoryAllocator::RemoveMemoryAllocationCallback(
void MemoryAllocator::ReportStatistics() {
intptr_t size = Size();
float pct = static_cast<float>(capacity_ - size) / capacity_;
PrintF(" capacity: %" V8_PTR_PREFIX
"d"
", used: %" V8_PTR_PREFIX
"d"
PrintF(" capacity: %" V8PRIdPTR ", used: %" V8PRIdPTR
", available: %%%d\n\n",
capacity_, size, static_cast<int>(pct * 100));
}
@ -2062,9 +2059,7 @@ void NewSpace::ReportStatistics() {
#ifdef DEBUG
if (FLAG_heap_stats) {
float pct = static_cast<float>(Available()) / TotalCapacity();
PrintF(" capacity: %" V8_PTR_PREFIX
"d"
", available: %" V8_PTR_PREFIX "d, %%%d\n",
PrintF(" capacity: %" V8PRIdPTR ", available: %" V8PRIdPTR ", %%%d\n",
TotalCapacity(), Available(), static_cast<int>(pct * 100));
PrintF("\n Object Histogram:\n");
for (int i = 0; i <= LAST_TYPE; i++) {
@ -2790,11 +2785,8 @@ void PagedSpace::CollectCodeStatistics() {
void PagedSpace::ReportStatistics() {
int pct = static_cast<int>(Available() * 100 / Capacity());
PrintF(" capacity: %" V8_PTR_PREFIX
"d"
", waste: %" V8_PTR_PREFIX
"d"
", available: %" V8_PTR_PREFIX "d, %%%d\n",
PrintF(" capacity: %" V8PRIdPTR ", waste: %" V8PRIdPTR
", available: %" V8PRIdPTR ", %%%d\n",
Capacity(), Waste(), Available(), pct);
if (heap()->mark_compact_collector()->sweeping_in_progress()) {
@ -3090,7 +3082,7 @@ void LargeObjectSpace::Print() {
void LargeObjectSpace::ReportStatistics() {
PrintF(" size: %" V8_PTR_PREFIX "d\n", size_);
PrintF(" size: %" V8PRIdPTR "\n", size_);
int num_objects = 0;
ClearHistograms(heap()->isolate());
LargeObjectIterator it(this);
@ -3101,7 +3093,7 @@ void LargeObjectSpace::ReportStatistics() {
PrintF(
" number of objects %d, "
"size of objects %" V8_PTR_PREFIX "d\n",
"size of objects %" V8PRIdPTR "\n",
num_objects, objects_size_);
if (num_objects > 0) ReportHistogram(heap()->isolate(), false);
}

View File

@ -8,6 +8,7 @@
#if V8_TARGET_ARCH_IA32
#include "src/base/compiler-specific.h"
#include "src/disasm.h"
namespace disasm {
@ -389,8 +390,7 @@ class DisassemblerIA32 {
int MemoryFPUInstruction(int escape_opcode, int regop, byte* modrm_start);
int RegisterFPUInstruction(int escape_opcode, byte modrm_byte);
int AVXInstruction(byte* data);
void AppendToBuffer(const char* format, ...);
PRINTF_FORMAT(2, 3) void AppendToBuffer(const char* format, ...);
void UnimplementedInstruction() {
if (abort_on_unimplemented_) {
@ -1274,7 +1274,7 @@ int DisassemblerIA32::InstructionDecode(v8::internal::Vector<char> out_buffer,
const InstructionDesc& idesc = instruction_table_->Get(*data);
switch (idesc.type) {
case ZERO_OPERANDS_INSTR:
AppendToBuffer(idesc.mnem);
AppendToBuffer("%s", idesc.mnem);
data++;
break;

View File

@ -2924,7 +2924,7 @@ void Isolate::CheckDetachedContextsAfterGC() {
DCHECK(detached_contexts->get(i + 1)->IsWeakCell());
WeakCell* cell = WeakCell::cast(detached_contexts->get(i + 1));
if (mark_sweeps > 3) {
PrintF("detached context 0x%p\n survived %d GCs (leak?)\n",
PrintF("detached context %p\n survived %d GCs (leak?)\n",
static_cast<void*>(cell->value()), mark_sweeps);
}
}

View File

@ -164,11 +164,7 @@ void Log::MessageBuilder::Append(String* str) {
}
}
void Log::MessageBuilder::AppendAddress(Address addr) {
Append("0x%" V8PRIxPTR, addr);
}
void Log::MessageBuilder::AppendAddress(Address addr) { Append("%p", addr); }
void Log::MessageBuilder::AppendSymbolName(Symbol* symbol) {
DCHECK(symbol);

View File

@ -10,6 +10,7 @@
#include <cstdarg>
#include "src/allocation.h"
#include "src/base/compiler-specific.h"
#include "src/base/platform/mutex.h"
#include "src/flags.h"
@ -62,10 +63,10 @@ class Log {
~MessageBuilder() { }
// Append string data to the log message.
void Append(const char* format, ...);
void PRINTF_FORMAT(2, 3) Append(const char* format, ...);
// Append string data to the log message.
void AppendVA(const char* format, va_list args);
void PRINTF_FORMAT(2, 0) AppendVA(const char* format, va_list args);
// Append a character to the log message.
void Append(const char c);

View File

@ -284,12 +284,11 @@ void PerfBasicLogger::LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo*,
return;
}
base::OS::FPrint(perf_output_handle_, "%llx %x %.*s\n",
reinterpret_cast<uint64_t>(code->instruction_start()),
code->instruction_size(), length, name);
base::OS::FPrint(perf_output_handle_, "%p %x %.*s\n",
code->instruction_start(), code->instruction_size(), length,
name);
}
// Low-level logging support.
#define LL_LOG(Call) if (ll_logger_) ll_logger_->Call;
@ -789,7 +788,7 @@ void Logger::UncheckedIntEvent(const char* name, int value) {
void Logger::UncheckedIntPtrTEvent(const char* name, intptr_t value) {
if (!log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
msg.Append("%s,%" V8_PTR_PREFIX "d", name, value);
msg.Append("%s,%" V8PRIdPTR, name, value);
msg.WriteToLogFile();
}
@ -797,7 +796,7 @@ void Logger::UncheckedIntPtrTEvent(const char* name, intptr_t value) {
void Logger::HandleEvent(const char* name, Object** location) {
if (!log_->IsEnabled() || !FLAG_log_handles) return;
Log::MessageBuilder msg(log_);
msg.Append("%s,0x%" V8PRIxPTR, name, location);
msg.Append("%s,%p", name, location);
msg.WriteToLogFile();
}
@ -838,7 +837,7 @@ void Logger::CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta) {
if (!log_->IsEnabled() || !FLAG_log_internal_timer_events) return;
Log::MessageBuilder msg(log_);
int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds());
msg.Append("code-deopt,%ld,%d", since_epoch, code->CodeSize());
msg.Append("code-deopt,%d,%d", since_epoch, code->CodeSize());
msg.WriteToLogFile();
}
@ -848,7 +847,7 @@ void Logger::CurrentTimeEvent() {
DCHECK(FLAG_log_timer_events || FLAG_prof_cpp);
Log::MessageBuilder msg(log_);
int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds());
msg.Append("current-time,%ld", since_epoch);
msg.Append("current-time,%d", since_epoch);
msg.WriteToLogFile();
}
@ -1008,8 +1007,7 @@ void Logger::ApiEntryCall(const char* name) {
void Logger::NewEvent(const char* name, void* object, size_t size) {
if (!log_->IsEnabled() || !FLAG_log) return;
Log::MessageBuilder msg(log_);
msg.Append("new,%s,0x%" V8PRIxPTR ",%u", name, object,
static_cast<unsigned int>(size));
msg.Append("new,%s,%p,%u", name, object, static_cast<unsigned int>(size));
msg.WriteToLogFile();
}
@ -1017,7 +1015,7 @@ void Logger::NewEvent(const char* name, void* object, size_t size) {
void Logger::DeleteEvent(const char* name, void* object) {
if (!log_->IsEnabled() || !FLAG_log) return;
Log::MessageBuilder msg(log_);
msg.Append("delete,%s,0x%" V8PRIxPTR, name, object);
msg.Append("delete,%s,%p", name, object);
msg.WriteToLogFile();
}
@ -1037,12 +1035,12 @@ void Logger::CallbackEventInternal(const char* prefix, Name* name,
} else {
Symbol* symbol = Symbol::cast(name);
if (symbol->name()->IsUndefined()) {
msg.Append(",1,symbol(hash %x)", prefix, symbol->Hash());
msg.Append(",1,symbol(hash %x)", symbol->Hash());
} else {
base::SmartArrayPointer<char> str =
String::cast(symbol->name())
->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
msg.Append(",1,symbol(\"%s\" hash %x)", prefix, str.get(),
msg.Append(",1,symbol(\"%s%s\" hash %x)", prefix, str.get(),
symbol->Hash());
}
}
@ -1386,7 +1384,7 @@ void Logger::TickEvent(TickSample* sample, bool overflow) {
Log::MessageBuilder msg(log_);
msg.Append("%s,", kLogEventsNames[TICK_EVENT]);
msg.AppendAddress(sample->pc);
msg.Append(",%ld", static_cast<int>(timer_.Elapsed().InMicroseconds()));
msg.Append(",%d", static_cast<int>(timer_.Elapsed().InMicroseconds()));
if (sample->has_external_callback) {
msg.Append(",1,");
msg.AppendAddress(sample->external_callback_entry);

View File

@ -8,6 +8,7 @@
#include <string>
#include "src/allocation.h"
#include "src/base/compiler-specific.h"
#include "src/base/platform/elapsed-timer.h"
#include "src/base/platform/platform.h"
#include "src/objects.h"
@ -354,7 +355,7 @@ class Logger {
// Emits a profiler tick event. Used by the profiler thread.
void TickEvent(TickSample* sample, bool overflow);
void ApiEvent(const char* name, ...);
PRINTF_FORMAT(2, 3) void ApiEvent(const char* format, ...);
// Logs a StringEvent regardless of whether FLAG_log is true.
void UncheckedStringEvent(const char* name, const char* value);

View File

@ -149,8 +149,7 @@ void AddressToTraceMap::Clear() {
void AddressToTraceMap::Print() {
PrintF("[AddressToTraceMap (%" V8_SIZET_PREFIX V8PRIuPTR "): \n",
ranges_.size());
PrintF("[AddressToTraceMap (%" PRIuS "): \n", ranges_.size());
for (RangeMap::iterator it = ranges_.begin(); it != ranges_.end(); ++it) {
PrintF("[%p - %p] => %u\n", it->second.start, it->first,
it->second.trace_node_id);

View File

@ -2247,9 +2247,9 @@ HeapEntry* BasicHeapEntriesAllocator::AllocateEntry(HeapThing ptr) {
intptr_t elements = info->GetElementCount();
intptr_t size = info->GetSizeInBytes();
const char* name = elements != -1
? names_->GetFormatted(
"%s / %" V8_PTR_PREFIX "d entries", info->GetLabel(), elements)
: names_->GetCopy(info->GetLabel());
? names_->GetFormatted("%s / %" V8PRIdPTR " entries",
info->GetLabel(), elements)
: names_->GetCopy(info->GetLabel());
return snapshot_->AddEntry(
entries_type_,
name,

View File

@ -229,12 +229,13 @@ void ProfileNode::Print(int indent) {
base::OS::Print("\n");
for (size_t i = 0; i < deopt_infos_.size(); ++i) {
CpuProfileDeoptInfo& info = deopt_infos_[i];
base::OS::Print(
"%*s;;; deopted at script_id: %d position: %d with reason '%s'.\n",
indent + 10, "", info.stack[0].script_id, info.stack[0].position,
info.deopt_reason);
base::OS::Print("%*s;;; deopted at script_id: %d position: %" PRIuS
" with reason '%s'.\n",
indent + 10, "", info.stack[0].script_id,
info.stack[0].position, info.deopt_reason);
for (size_t index = 1; index < info.stack.size(); ++index) {
base::OS::Print("%*s;;; Inline point: script_id %d position: %d.\n",
base::OS::Print("%*s;;; Inline point: script_id %d position: %" PRIuS
".\n",
indent + 10, "", info.stack[index].script_id,
info.stack[index].position);
}

View File

@ -6,6 +6,7 @@
#define V8_PROFILER_STRINGS_STORAGE_H_
#include "src/allocation.h"
#include "src/base/compiler-specific.h"
#include "src/hashmap.h"
namespace v8 {
@ -19,7 +20,8 @@ class StringsStorage {
~StringsStorage();
const char* GetCopy(const char* src);
const char* GetFormatted(const char* format, ...);
PRINTF_FORMAT(2, 3) const char* GetFormatted(const char* format, ...);
PRINTF_FORMAT(2, 0)
const char* GetVFormatted(const char* format, va_list args);
const char* GetName(Name* name);
const char* GetName(int index);

View File

@ -71,15 +71,15 @@ void Serializer::OutputStatistics(const char* name) {
for (int space = 0; space < kNumberOfPreallocatedSpaces; space++) {
size_t s = pending_chunk_[space];
for (uint32_t chunk_size : completed_chunks_[space]) s += chunk_size;
PrintF("%16" V8_SIZET_PREFIX V8_PTR_PREFIX "d", s);
PrintF("%16" PRIuS, s);
}
PrintF("%16d\n", large_objects_total_size_);
#ifdef OBJECT_PRINT
PrintF(" Instance types (count and bytes):\n");
#define PRINT_INSTANCE_TYPE(Name) \
if (instance_type_count_[Name]) { \
PrintF("%10d %10" V8_SIZET_PREFIX V8_PTR_PREFIX "d %s\n", \
instance_type_count_[Name], instance_type_size_[Name], #Name); \
#define PRINT_INSTANCE_TYPE(Name) \
if (instance_type_count_[Name]) { \
PrintF("%10d %10" PRIuS " %s\n", instance_type_count_[Name], \
instance_type_size_[Name], #Name); \
}
INSTANCE_TYPE_LIST(PRINT_INSTANCE_TYPE)
#undef PRINT_INSTANCE_TYPE

View File

@ -13,6 +13,7 @@
#include "include/v8.h"
#include "src/allocation.h"
#include "src/base/bits.h"
#include "src/base/compiler-specific.h"
#include "src/base/logging.h"
#include "src/base/macros.h"
#include "src/base/platform/platform.h"
@ -908,42 +909,21 @@ class TokenDispenserForFinally {
// ----------------------------------------------------------------------------
// I/O support.
#if __GNUC__ >= 4
// On gcc we can ask the compiler to check the types of %d-style format
// specifiers and their associated arguments. TODO(erikcorry) fix this
// so it works on MacOSX.
#if defined(__MACH__) && defined(__APPLE__)
#define PRINTF_CHECKING
#define FPRINTF_CHECKING
#define PRINTF_METHOD_CHECKING
#define FPRINTF_METHOD_CHECKING
#else // MacOsX.
#define PRINTF_CHECKING __attribute__ ((format (printf, 1, 2)))
#define FPRINTF_CHECKING __attribute__ ((format (printf, 2, 3)))
#define PRINTF_METHOD_CHECKING __attribute__ ((format (printf, 2, 3)))
#define FPRINTF_METHOD_CHECKING __attribute__ ((format (printf, 3, 4)))
#endif
#else
#define PRINTF_CHECKING
#define FPRINTF_CHECKING
#define PRINTF_METHOD_CHECKING
#define FPRINTF_METHOD_CHECKING
#endif
// Our version of printf().
void PRINTF_CHECKING PrintF(const char* format, ...);
void FPRINTF_CHECKING PrintF(FILE* out, const char* format, ...);
void PRINTF_FORMAT(1, 2) PrintF(const char* format, ...);
void PRINTF_FORMAT(2, 3) PrintF(FILE* out, const char* format, ...);
// Prepends the current process ID to the output.
void PRINTF_CHECKING PrintPID(const char* format, ...);
void PRINTF_FORMAT(1, 2) PrintPID(const char* format, ...);
// Prepends the current process ID and given isolate pointer to the output.
void PrintIsolate(void* isolate, const char* format, ...);
void PRINTF_FORMAT(2, 3) PrintIsolate(void* isolate, const char* format, ...);
// Safe formatting print. Ensures that str is always null-terminated.
// Returns the number of chars written, or -1 if output was truncated.
int FPRINTF_CHECKING SNPrintF(Vector<char> str, const char* format, ...);
int VSNPrintF(Vector<char> str, const char* format, va_list args);
int PRINTF_FORMAT(2, 3) SNPrintF(Vector<char> str, const char* format, ...);
int PRINTF_FORMAT(2, 0)
VSNPrintF(Vector<char> str, const char* format, va_list args);
void StrNCpy(Vector<char> dest, const char* src, size_t n);
@ -1446,10 +1426,11 @@ class StringBuilder : public SimpleStringBuilder {
StringBuilder(char* buffer, int size) : SimpleStringBuilder(buffer, size) { }
// Add formatted contents to the builder just like printf().
void AddFormatted(const char* format, ...);
void PRINTF_FORMAT(2, 3) AddFormatted(const char* format, ...);
// Add formatted contents like printf based on a va_list.
void AddFormattedList(const char* format, va_list list);
void PRINTF_FORMAT(2, 0) AddFormattedList(const char* format, va_list list);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder);
};

View File

@ -5,9 +5,11 @@
#ifndef V8_WASM_DECODER_H_
#define V8_WASM_DECODER_H_
#include "src/base/compiler-specific.h"
#include "src/base/smart-pointers.h"
#include "src/flags.h"
#include "src/signature.h"
#include "src/utils.h"
#include "src/wasm/wasm-result.h"
#include "src/zone-containers.h"
@ -47,7 +49,7 @@ class Decoder {
inline bool check(const byte* base, int offset, int length, const char* msg) {
DCHECK_GE(base, start_);
if ((base + offset + length) > limit_) {
error(base, base + offset, msg);
error(base, base + offset, "%s", msg);
return false;
}
return true;
@ -258,12 +260,13 @@ class Decoder {
}
}
void error(const char* msg) { error(pc_, nullptr, msg); }
void error(const char* msg) { error(pc_, nullptr, "%s", msg); }
void error(const byte* pc, const char* msg) { error(pc, nullptr, msg); }
void error(const byte* pc, const char* msg) { error(pc, nullptr, "%s", msg); }
// Sets internal error state.
void error(const byte* pc, const byte* pt, const char* format, ...) {
void PRINTF_FORMAT(4, 5)
error(const byte* pc, const byte* pt, const char* format, ...) {
if (ok()) {
#if DEBUG
if (FLAG_wasm_break_on_decoder_error) {
@ -392,7 +395,7 @@ class Decoder {
return 0;
}
if ((b & 0x80) != 0) {
error(base, ptr, msg);
error(base, ptr, "%s", msg);
return 0;
}
}

View File

@ -5,6 +5,7 @@
#ifndef V8_WASM_RESULT_H_
#define V8_WASM_RESULT_H_
#include "src/base/compiler-specific.h"
#include "src/base/smart-pointers.h"
#include "src/globals.h"
@ -93,13 +94,13 @@ class ErrorThrower {
ErrorThrower(Isolate* isolate, const char* context)
: isolate_(isolate), context_(context), error_(false) {}
void Error(const char* fmt, ...);
PRINTF_FORMAT(2, 3) void Error(const char* fmt, ...);
template <typename T>
void Failed(const char* error, Result<T>& result) {
std::ostringstream str;
str << error << result;
return Error(str.str().c_str());
return Error("%s", str.str().c_str());
}
bool error() const { return error_; }

View File

@ -8,6 +8,7 @@
#if V8_TARGET_ARCH_X64
#include "src/base/compiler-specific.h"
#include "src/base/lazy-instance.h"
#include "src/disasm.h"
@ -479,7 +480,7 @@ class DisassemblerX64 {
int MemoryFPUInstruction(int escape_opcode, int regop, byte* modrm_start);
int RegisterFPUInstruction(int escape_opcode, byte modrm_byte);
int AVXInstruction(byte* data);
void AppendToBuffer(const char* format, ...);
PRINTF_FORMAT(2, 3) void AppendToBuffer(const char* format, ...);
void UnimplementedInstruction() {
if (abort_on_unimplemented_) {
@ -618,7 +619,7 @@ int DisassemblerX64::PrintImmediate(byte* data, OperandSize size) {
value = 0; // Initialize variables on all paths to satisfy the compiler.
count = 0;
}
AppendToBuffer("%" V8_PTR_PREFIX "x", value);
AppendToBuffer("%" PRIx64, value);
return count;
}
@ -1999,7 +2000,7 @@ int DisassemblerX64::InstructionDecode(v8::internal::Vector<char> out_buffer,
if (rex_w()) AppendToBuffer("REX.W ");
AppendToBuffer("%s%c", idesc.mnem, operand_size_code());
} else {
AppendToBuffer("%s", idesc.mnem, operand_size_code());
AppendToBuffer("%s%c", idesc.mnem, operand_size_code());
}
data++;
break;
@ -2334,9 +2335,7 @@ int DisassemblerX64::InstructionDecode(v8::internal::Vector<char> out_buffer,
default:
UNREACHABLE();
}
AppendToBuffer("test%c rax,0x%" V8_PTR_PREFIX "x",
operand_size_code(),
value);
AppendToBuffer("test%c rax,0x%" PRIx64, operand_size_code(), value);
break;
}
case 0xD1: // fall through

View File

@ -8,6 +8,7 @@
#if V8_TARGET_ARCH_X87
#include "src/base/compiler-specific.h"
#include "src/disasm.h"
namespace disasm {
@ -325,8 +326,7 @@ class DisassemblerX87 {
int FPUInstruction(byte* data);
int MemoryFPUInstruction(int escape_opcode, int regop, byte* modrm_start);
int RegisterFPUInstruction(int escape_opcode, byte modrm_byte);
void AppendToBuffer(const char* format, ...);
PRINTF_FORMAT(2, 3) void AppendToBuffer(const char* format, ...);
void UnimplementedInstruction() {
if (abort_on_unimplemented_) {
@ -948,7 +948,7 @@ int DisassemblerX87::InstructionDecode(v8::internal::Vector<char> out_buffer,
const InstructionDesc& idesc = instruction_table_->Get(*data);
switch (idesc.type) {
case ZERO_OPERANDS_INSTR:
AppendToBuffer(idesc.mnem);
AppendToBuffer("%s", idesc.mnem);
data++;
break;

View File

@ -2296,16 +2296,20 @@ TEST(TestSizeOfObjectsVsHeapIteratorPrecision) {
// on the heap.
if (size_of_objects_1 > size_of_objects_2) {
intptr_t delta = size_of_objects_1 - size_of_objects_2;
PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, "
"Iterator: %" V8_PTR_PREFIX "d, "
"delta: %" V8_PTR_PREFIX "d\n",
PrintF("Heap::SizeOfObjects: %" V8PRIdPTR
", "
"Iterator: %" V8PRIdPTR
", "
"delta: %" V8PRIdPTR "\n",
size_of_objects_1, size_of_objects_2, delta);
CHECK_GT(size_of_objects_1 / 20, delta);
} else {
intptr_t delta = size_of_objects_2 - size_of_objects_1;
PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, "
"Iterator: %" V8_PTR_PREFIX "d, "
"delta: %" V8_PTR_PREFIX "d\n",
PrintF("Heap::SizeOfObjects: %" V8PRIdPTR
", "
"Iterator: %" V8PRIdPTR
", "
"delta: %" V8PRIdPTR "\n",
size_of_objects_1, size_of_objects_2, delta);
CHECK_GT(size_of_objects_2 / 20, delta);
}

View File

@ -375,9 +375,8 @@ TEST(LogCallbacks) {
ObjMethod1_entry = *FUNCTION_ENTRYPOINT_ADDRESS(ObjMethod1_entry);
#endif
i::EmbeddedVector<char, 100> ref_data;
i::SNPrintF(ref_data,
"code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"method1\"",
reinterpret_cast<intptr_t>(ObjMethod1_entry));
i::SNPrintF(ref_data, "code-creation,Callback,-2,%p,1,\"method1\"",
ObjMethod1_entry);
CHECK(StrNStr(log.start(), ref_data.start(), log.length()));
log.Dispose();
@ -429,8 +428,8 @@ TEST(LogAccessorCallbacks) {
#endif
EmbeddedVector<char, 100> prop1_getter_record;
i::SNPrintF(prop1_getter_record,
"code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"get prop1\"",
reinterpret_cast<intptr_t>(Prop1Getter_entry));
"code-creation,Callback,-2,%p,1,\"get prop1\"",
Prop1Getter_entry);
CHECK(StrNStr(log.start(), prop1_getter_record.start(), log.length()));
Address Prop1Setter_entry = reinterpret_cast<Address>(Prop1Setter);
@ -439,8 +438,8 @@ TEST(LogAccessorCallbacks) {
#endif
EmbeddedVector<char, 100> prop1_setter_record;
i::SNPrintF(prop1_setter_record,
"code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"set prop1\"",
reinterpret_cast<intptr_t>(Prop1Setter_entry));
"code-creation,Callback,-2,%p,1,\"set prop1\"",
Prop1Setter_entry);
CHECK(StrNStr(log.start(), prop1_setter_record.start(), log.length()));
Address Prop2Getter_entry = reinterpret_cast<Address>(Prop2Getter);
@ -449,8 +448,8 @@ TEST(LogAccessorCallbacks) {
#endif
EmbeddedVector<char, 100> prop2_getter_record;
i::SNPrintF(prop2_getter_record,
"code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"get prop2\"",
reinterpret_cast<intptr_t>(Prop2Getter_entry));
"code-creation,Callback,-2,%p,1,\"get prop2\"",
Prop2Getter_entry);
CHECK(StrNStr(log.start(), prop2_getter_record.start(), log.length()));
log.Dispose();
}

View File

@ -1629,6 +1629,7 @@
'../../src/base/division-by-constant.cc',
'../../src/base/division-by-constant.h',
'../../src/base/flags.h',
'../../src/base/format-macros.h',
'../../src/base/functional.cc',
'../../src/base/functional.h',
'../../src/base/iterator.h',