Commit 068617d6 by Jamie Madill Committed by Commit Bot

Fix debug message formatting.

Also includes a refactor of GLenum utils. Bug: angleproject:5131 Change-Id: Ic2d974ef5612b3609ae66bcca087cc0442f43888 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2447042Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 2d9d904e
{
"scripts/gen_gl_enum_utils.py":
"af9ec09ac89a73c9fe0dd510a1db4b38",
"05fa5314e0a9e4974846f03a3f0c7a05",
"scripts/gl.xml":
"e74a595068cbdd6064300be1e71b7cc9",
"scripts/gl_angle_ext.xml":
......@@ -8,7 +8,7 @@
"scripts/registry_xml.py":
"e2e5d79fa0e069f8cfb00af8648899ed",
"src/libANGLE/gl_enum_utils_autogen.cpp":
"375cbe993124522fc0668b9feb74f234",
"823b9cac0022281ac7ea5aa7b23a3a66",
"src/libANGLE/gl_enum_utils_autogen.h":
"dd54f34be733affcb994fc315c3b972d"
}
\ No newline at end of file
......@@ -52,10 +52,6 @@ template_gl_enums_source = """// GENERATED FILE - DO NOT EDIT.
#include "libANGLE/gl_enum_utils.h"
#include <sstream>
#include "common/bitset_utils.h"
namespace gl
{{
const char *GLenumToString(GLenumGroup enumGroup, unsigned int value)
......@@ -67,33 +63,6 @@ const char *GLenumToString(GLenumGroup enumGroup, unsigned int value)
return kUnknownGLenumString;
}}
}}
std::string GLbitfieldToString(GLenumGroup enumGroup, unsigned int value)
{{
std::stringstream st;
if (value == 0)
{{
return "0";
}}
const angle::BitSet<32> bitSet(value);
bool first = true;
for (const auto index : bitSet)
{{
if (!first)
{{
st << " | ";
}}
first = false;
unsigned int mask = 1u << index;
OutputGLenumString(st, enumGroup, mask);
}}
return st.str();
}}
}} // namespace gl
"""
......
......@@ -49,26 +49,16 @@ std::string ArrayIndexString(const std::vector<unsigned int> &indices)
size_t FormatStringIntoVector(const char *fmt, va_list vararg, std::vector<char> &outBuffer)
{
// The state of the va_list passed to vsnprintf is undefined after the call,
// do a copy since we don't want to interfere with vararg usage inside the caller.
va_list varargCopy;
va_copy(varargCopy, vararg);
// Attempt to just print to the current buffer
int len = vsnprintf(&(outBuffer.front()), outBuffer.size(), fmt, varargCopy);
va_end(varargCopy);
int len = vsnprintf(nullptr, 0, fmt, vararg);
ASSERT(len >= 0);
if (static_cast<size_t>(len) >= outBuffer.size())
{
// Buffer was not large enough, resize it
outBuffer.resize(len + 1);
outBuffer.resize(len + 1, 0);
// Print again
va_copy(varargCopy, vararg);
len = vsnprintf(&(outBuffer.front()), outBuffer.size(), fmt, varargCopy);
va_end(varargCopy);
ASSERT(len >= 0);
}
len = vsnprintf(outBuffer.data(), outBuffer.size(), fmt, varargCopy);
va_end(varargCopy);
ASSERT(len >= 0);
return static_cast<size_t>(len);
}
......@@ -28,6 +28,7 @@
#include "anglebase/no_destructor.h"
#include "common/Optional.h"
#include "common/angleutils.h"
#include "common/entry_points_enum_autogen.h"
#include "common/system_utils.h"
namespace gl
......@@ -123,7 +124,7 @@ ScopedPerfEventHelper::ScopedPerfEventHelper(gl::Context *context,
gl::EntryPoint entryPoint,
const char *format,
...)
: mContext(context), mEntryPoint(entryPoint), mFunctionName(nullptr)
: mContext(context), mEntryPoint(entryPoint), mFunctionName(GetEntryPointName(entryPoint))
{
bool dbgTrace = DebugAnnotationsActive();
#if !defined(ANGLE_ENABLE_DEBUG_TRACE)
......@@ -135,12 +136,12 @@ ScopedPerfEventHelper::ScopedPerfEventHelper(gl::Context *context,
va_list vararg;
va_start(vararg, format);
std::vector<char> buffer(512);
std::vector<char> buffer;
size_t len = FormatStringIntoVector(format, vararg, buffer);
ANGLE_LOG(EVENT) << std::string(&buffer[0], len);
// Pull function name from variable args
mFunctionName = va_arg(vararg, const char *);
va_end(vararg);
ANGLE_LOG(EVENT) << std::string(&buffer[0], len);
if (dbgTrace)
{
g_debugAnnotator->beginEvent(context, entryPoint, mFunctionName, buffer.data());
......
......@@ -117,7 +117,7 @@ std::string FormatString(const char *fmt, ...)
va_list vararg;
va_start(vararg, fmt);
std::vector<char> buffer(512);
std::vector<char> buffer;
size_t len = FormatStringIntoVector(fmt, vararg, buffer);
va_end(vararg);
......
......@@ -8,7 +8,10 @@
#include "libANGLE/gl_enum_utils.h"
#include "common/bitset_utils.h"
#include <iomanip>
#include <sstream>
namespace gl
{
......@@ -54,4 +57,30 @@ const char *GLbooleanToString(unsigned int value)
return kUnknownGLenumString;
}
}
std::string GLbitfieldToString(GLenumGroup enumGroup, unsigned int value)
{
std::stringstream st;
if (value == 0)
{
return "0";
}
const angle::BitSet<32> bitSet(value);
bool first = true;
for (const auto index : bitSet)
{
if (!first)
{
st << " | ";
}
first = false;
unsigned int mask = 1u << index;
OutputGLenumString(st, enumGroup, mask);
}
return st.str();
}
} // namespace gl
......@@ -12,10 +12,6 @@
#include "libANGLE/gl_enum_utils.h"
#include <sstream>
#include "common/bitset_utils.h"
namespace gl
{
const char *GLenumToString(GLenumGroup enumGroup, unsigned int value)
......@@ -4083,30 +4079,4 @@ const char *GLenumToString(GLenumGroup enumGroup, unsigned int value)
return kUnknownGLenumString;
}
}
std::string GLbitfieldToString(GLenumGroup enumGroup, unsigned int value)
{
std::stringstream st;
if (value == 0)
{
return "0";
}
const angle::BitSet<32> bitSet(value);
bool first = true;
for (const auto index : bitSet)
{
if (!first)
{
st << " | ";
}
first = false;
unsigned int mask = 1u << index;
OutputGLenumString(st, enumGroup, mask);
}
return st.str();
}
} // namespace gl
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment