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

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

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);

This comment has been minimized.

@KyleSanderson

KyleSanderson Sep 18, 2017
Member

nit: initialization should begin here.

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

This comment has been minimized.

@KyleSanderson

KyleSanderson Sep 18, 2017
Member

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);

This comment has been minimized.

@KyleSanderson

KyleSanderson Sep 18, 2017
Member

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());

This comment has been minimized.

@KyleSanderson

KyleSanderson Sep 18, 2017
Member

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());

This comment has been minimized.

@KyleSanderson

KyleSanderson Sep 18, 2017
Member

ditto on the formatting issue.

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

This comment has been minimized.

@KyleSanderson

KyleSanderson Sep 18, 2017
Member

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

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

}
}
}


This comment has been minimized.

@KyleSanderson

KyleSanderson Sep 19, 2017
Member

nit: weird newline

return 0;
}


This comment has been minimized.

@KyleSanderson

KyleSanderson Sep 19, 2017
Member

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());
}
}

This comment has been minimized.

@KyleSanderson

KyleSanderson Dec 31, 2017
Member

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
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@Headline Headline deleted the Headline:sync-upstream branch Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.