Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LogStackTrace Native (#684) #685

Merged
merged 1 commit into from Jun 20, 2018
Merged

Add LogStackTrace Native (#684) #685

merged 1 commit into from Jun 20, 2018

Conversation

Headline
Copy link
Member

@Headline Headline commented Sep 17, 2017

In order for this to be merged, this pr for sourcepawn must be merged.

Essentially this adds pull request adds LogStackTrace, which will serve as a debugging function that outputs a stack trace where the native is called, but does not halt execution. For more info: see #684

#include <sourcemod>

public void OnPluginStart()
{
	SomeFunction();
}

void SomeFunction()
{
	SomeFunction2();
}

void SomeFunction2()
{
	LogStackTrace("LogStackTrace%i %.2f", 4, 10.0)
	SetFailState("SetFailState %i %.2f", 4, 10.0)
}

will output in errors

L 09/17/2017 - 15:07:55: [SM] Stack trace requested: LogStackTrace 4 10.00
L 09/17/2017 - 15:07:55: [SM] Call stack trace:
L 09/17/2017 - 15:07:55: [SM]   [0] LogStackTrace
L 09/17/2017 - 15:07:55: [SM]   [1] Line 15, C:\Users\Micha\Desktop\sourcemod\sourcemod\build\package\addons\sourcemod\Test.sp::SomeFunction2
L 09/17/2017 - 15:07:55: [SM]   [2] Line 10, C:\Users\Micha\Desktop\sourcemod\sourcemod\build\package\addons\sourcemod\Test.sp::SomeFunction
L 09/17/2017 - 15:07:55: [SM]   [3] Line 5, C:\Users\Micha\Desktop\sourcemod\sourcemod\build\package\addons\sourcemod\Test.sp::OnPluginStart
L 09/17/2017 - 15:07:55: [SM] Exception reported: SetFailState 4 10.00
L 09/17/2017 - 15:07:55: [SM] Blaming: test.smx
L 09/17/2017 - 15:07:55: [SM] Call stack trace:
L 09/17/2017 - 15:07:55: [SM]   [0] SetFailState
L 09/17/2017 - 15:07:55: [SM]   [1] Line 16, C:\Users\Micha\Desktop\sourcemod\sourcemod\build\package\addons\sourcemod\Test.sp::SomeFunction2
L 09/17/2017 - 15:07:55: [SM]   [2] Line 10, C:\Users\Micha\Desktop\sourcemod\sourcemod\build\package\addons\sourcemod\Test.sp::SomeFunction
L 09/17/2017 - 15:07:55: [SM]   [3] Line 5, C:\Users\Micha\Desktop\sourcemod\sourcemod\build\package\addons\sourcemod\Test.sp::OnPluginStart

Copy link
Member

@KyleSanderson KyleSanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thankful this isn't actually RequestStackFrame, but RequestStackTrace. I think this would confuse the hell out of people if it was the former :-P

ke::Vector<ke::AString> arr;

IFrameIterator *it = pContext->CreateFrameIterator();
arr = g_DbgReporter.GetStackTrace(it);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: initialization should begin here.

IFrameIterator *it = pContext->CreateFrameIterator();
arr = g_DbgReporter.GetStackTrace(it);
pContext->DestroyFrameIterator(it);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plugin calling this native should be present in the output, similar to SetFailState.

@@ -45,6 +47,7 @@ class DebugReport :
void ReportError(const IErrorReport &report, IFrameIterator &iter);
void OnDebugSpew(const char *msg, ...);
public:
ke::Vector<ke::AString> GetStackTrace(IFrameIterator *iter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: double space after the type.

ke::Vector<ke::AString> arr = GetStackTrace(&iter);
for (size_t i = 0; i < arr.length(); i++)
{
g_Logger.LogError(arr[i].chars());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're double formatting here, see Logger::LogError. Instead what you want to do is something like: g_Logger.LogError("%s", arr[i].chars());

g_Logger.LogError("[SM] Stack trace requested: %s", buffer);
for (size_t i = 0; i < arr.length(); i++)
{
g_Logger.LogError(arr[i].chars());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto on the formatting issue.

if (!iter.Done())
ke::Vector<ke::AString> DebugReport::GetStackTrace(IFrameIterator *iter)
{
char temp[1024];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget if we have a mapper, but we're limiting our stack traces here to 1024 characters from previously 3072. I'm not sure if this is desired?

Copy link
Member

@KyleSanderson KyleSanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm minus the nits (but they're nits); nice job.

}
}
}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: weird newline

return 0;
}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto on weird newline

@Headline Headline changed the title Add RequestStackFrame Native (#684) Add RequestStackTrace Native (#684) Sep 25, 2017
@Headline Headline changed the title Add RequestStackTrace Native (#684) Add LogStackTrace Native (#684) Sep 26, 2017
@Headline Headline closed this Oct 3, 2017
@Headline Headline reopened this Oct 3, 2017
{
g_Logger.LogError("%s", arr[i].chars());
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails to build currently because there's a cell_t expected to be returned but this function returns nothing.

@Headline Headline closed this Jun 19, 2018
@Headline Headline reopened this Jun 19, 2018
@KyleSanderson KyleSanderson merged commit 9ceb1af into alliedmodders:master Jun 20, 2018
@Headline Headline deleted the sync-upstream branch July 31, 2018 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants