ibm-information-center/dist/eclipse/plugins/i5OS.ic.apis_5.4.0.1/p0zdmpt.htm

355 lines
11 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
<title>Qp0zDumpTargetStack()--Dump Formatted Stack Trace Data of the Target
Thread</title>
<!-- Begin Header Records ========================================== -->
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<!-- Change History: -->
<!-- YYMMDD USERID Change description -->
<!-- Direct1 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
<!-- Edited by Kersten Feb 02 -->
<!-- This file has undergone html cleanup May 2002 by JET -->
<!-- End Header Records -->
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body>
<!-- Java sync-link -->
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
</script>
<a name="Top_Of_Page"></a>
<h2>Qp0zDumpTargetStack()--Dump Formatted Stack Trace Data of the Target
Thread</h2>
<div class="box" style="width: 60%;">
<br>
&nbsp;&nbsp;Syntax<br>
<pre>
#include &lt;qp0ztrc.h&gt;
int Qp0zDumpTargetStack(int <em>handle</em>,
const char <em>*label</em>);
</pre>
<br>
&nbsp;&nbsp;Service Program Name: QP0ZCPA<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: Conditional; see <a href="#USAGE_NOTES">Usage Notes</a>.<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <strong>Qp0zDumpTargetStack()</strong> function dumps a formatted
representation of the call stack of the target thread to the user trace. The
target thread is specified by <em>handle</em>, which can be filled in using the
<em>pthread_t</em> structure. The formatted call stack is labeled with the text
string specified by <em>label</em>. The formatted call stack shows the library,
program, module, and procedure information associated with each frame on the
call stack at the time the function was called.</p>
<p>The formatted dump of the target call stack shows the oldest entries first,
followed by newer entries.</p>
<p>For consistent results, ensure that the target thread specified in the <em>
handle</em> parameter is blocked or waiting for some resource and not actively
running.</p>
<p>If a target thread that is actively running is specified, the stack trace
information may be inconsistent.</p>
<p>An application should not use the tracing function in performance critical
code. These functions are intended for debugging exception or error conditions.
The user trace is a permanent user space object named <em>
QP0Z&lt;jobnumber&gt;</em> in the QUSRSYS library. The user trace is created
the first time any thread in a job writes trace output. See the Change User
Trace (CHGUSRTRC), Dump User Trace (DMPUSRTRC) and Delete User Trace
(DLTUSRTRC) CL commands for information about manipulating the user trace
properties and objects.</p>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong><em>handle</em></strong></dt>
<dd>(Input) A handle to the target thread.<br>
<br>
</dd>
<dt><strong><em>label</em></strong></dt>
<dd>(Input) A pointer to a string that is used to label the stack dump.</dd>
</dl>
<br>
<h3>Authorities</h3>
<p>None.</p>
<br>
<h3>Return Value</h3>
<table cellpadding="5">
<!-- cols="10 90" -->
<tr>
<td align="left" valign="top"><em>0</em></td>
<td align="left" valign="top"><strong>Qp0zDumpTargetStack()</strong> was
successful.</td>
</tr>
<tr>
<td align="left" valign="top"><em>value</em></td>
<td align="left" valign="top"><strong>Qp0zDumpTargetStack()</strong> was not
successful. The value returned is an errno indicating the failure.</td>
</tr>
</table>
<br>
<br>
<h3>Error Conditions</h3>
<p>If <strong>Qp0zDumpTargetStack()</strong> is not successful, the return
value usually indicates one of the following errors. Under some conditions, the
return value could indicate an error other than those listed here.</p>
<dl>
<dt><em>[EFAULT]</em></dt>
<dd>
<p>The address used for an argument is not correct.</p>
<p>In attempting to use an argument in a call, the system detected an address
that is not valid.</p>
<p>While attempting to access a parameter passed to this function, the system
detected an address that is not valid.</p>
</dd>
<dt><em>[ESRCH]</em></dt>
<dd>
<p>No item could be found that matches the specified value.</p>
</dd>
</dl>
<br>
<br>
<h3><a name="USAGE_NOTES">Usage Notes</a></h3>
<ol>
<li>No locks are held on the user trace between calls to the tracing functions.
The user trace can be deleted while in use. The next function that produces
trace output will create the user trace again.<br>
<br>
</li>
<li>If another job on the system has the same job number as an existing user
trace, the existing trace data is cleared, and the trace data from the new job
replaces it.<br>
<br>
</li>
<li>The <strong>Qp0zDumpTargetStack()</strong> can only safely be used against
a thread that is stopped or waiting for some activity to occur. If <strong>
Qp0zDumpTargetStack()</strong> is used with a thread that is actively running,
the output stack trace may show an inconsistent view of the call stack.<br>
<br>
</li>
<li>If the target thread has more than 128 call stack entries, <strong>
Qp0zDumpTargetStack()</strong> returns after dumping the first 128 entries of
the call stack.<br>
<br>
</li>
<li>As the format of the user trace records can change, only the following CL
commands can be used to manipulate the user trace properties and objects:<br>
<ul>
<li>Change User Trace (CHGUSRTRC) can be used to change the characteristics of
the user trace.<br>
<br>
</li>
<li>Dump User Trace (DMPUSRTRC) can be used to dump trace records to a file or
to standard output.<br>
<br>
</li>
<li>Delete User Trace (DLTUSRTRC) can be used to delete the user trace
objects.</li>
</ul>
</li>
</ol>
<br>
<h3>Related Information</h3>
<ul>
<li><a href="p0zdmp.htm">Qp0zDump()</a>--Dump Formatted Storage Trace Data<br>
<br>
</li>
<li><a href="p0zdmps.htm">Qp0zDumpStack()</a>--Dump Formatted Stack Trace
Data<br>
<br>
</li>
<li><a href="p0zlog.htm">Qp0zLprintf()</a>--Print Formatted Job Log Data<br>
<br>
</li>
<li><a href="p0zprnt.htm">Qp0zUprintf()</a>--Print Formatted User Trace
Data</li>
</ul>
<br>
<h3>Example</h3>
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
for information pertaining to code examples.</p>
<p>The following example uses <strong>Qp0zDumpTargetStack()</strong> and
<strong>Qp0zUprintf()</strong> functions to produce trace output.</p>
<pre>
#define _MULTI_THREADED
#include &lt;pthread.h&gt;
#include &lt;milib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;errno.h&gt;
#include &lt;unistd.h&gt;
#include &lt;qp0ztrc.h&gt;
void *threadfunc(void *);
int main(int argc, char **argv)
{
int rc=0;
pthread_t thread;
Qp0zUprintf("Entering Testcase\n");
rc = pthread_create(&amp;thread, NULL, threadfunc, NULL);
sleep(2); /* Let the thread block */
/* If the other thread ends or is actively running (that is */
/* changing the call stack, you may get meaningless results in the*/
/* stack dump for the target thread.) */
Qp0zDumpTargetStack(thread.reservedHandle,
"Dumping target thread's stack\n");
Qp0zUprintf("Exit with return code of 0\n");
return 0;
}
void foo(void);
void bar(void);
void *threadfunc(void *parm)
{
Qp0zUprintf("Inside secondary thread\n");
foo();
return NULL;
}
void foo(void)
{
bar();
}
void bar(void)
{
Qp0zDumpStack("Thread dumping my own stack\n");
sleep(10); /* Ensure the thread is blocked */
}
</pre>
<br>
<h3>Trace Output:</h3>
<p>This trace output was generated after the test case was run by using the CL
command <strong>DMPUSRTRC JOB(107141/USER/TPZTSTK0) OUTPUT(*STDOUT)</strong>.
The above example program ran as job 107141/USER/TPZTSTK0.</p>
<p>Note the following in the trace output:</p>
<ol>
<li>Each trace record is indented by several spaces to aid in readability.
Trace records from different threads have different indentation levels.<br>
<br>
</li>
<li>Each trace record is identified by the hexadecimal thread ID, a colon, and
a timestamp. The timestamp can be used to aid in debugging of waiting or
looping threads. For example, the third trace record shown below, (the Entering
Testcase trace point) was created by thread 0x36, and occurred 0.595584 seconds
after the last full date and time label. This means that the trace record was
created on 23 January 1998 at 12:38:10.595584. A full date and time label is
placed between those trace points that occur during different whole
seconds.</li>
</ol>
<br>
<br>
<pre>
User Trace Dump for job 107141/USER/TPZTSTK0. Size: 300K, Wrapped 0 times.
--- 01/23/1998 12:38:10 ---
00000036:595584 Entering Testcase
00000037:598832 Inside secondary thread
00000037:599024 Stack Dump For Current Thread
00000037:599200 Stack: Thread dumping my own stack
00000037:695440 Stack: Library / Program Module Stmt Procedure
00000037:752984 Stack: QSYS / QLESPI QLECRTTH 774 : LE_Create_Thread2__FP12crtth_parm_t
00000037:805664 Stack: QSYS / QP0WPTHR QP0WPTHR 1006 : pthread_create_part2
00000037:805888 Stack: QP0WTEST / TPZTSTK0 TPZTSTK0 2 : threadfunc
00000037:806088 Stack: QP0WTEST / TPZTSTK0 TPZTSTK0 1 : foo
00000037:806288 Stack: QP0WTEST / TPZTSTK0 TPZTSTK0 1 : bar
00000037:806496 Stack: QSYS / QP0ZCPA QP0ZUDBG 85 : Qp0zDumpStack
00000037:848280 Stack: QSYS / QP0ZSCPA QP0ZSCPA 274 : Qp0zSUDumpStack
00000037:848504 Stack: QSYS / QP0ZSCPA QP0ZSCPA 285 : Qp0zSUDumpTargetStack
00000037:848616 Stack: Completed
--- 01/23/1998 12:38:12 ---
00000036:628272 Stack Dump For Target Thread: Handle 7 (0x00000007)
00000036:628464 Stack: Dumping target thread's stack
00000036:651608 Stack: Library / Program Module Stmt Procedure
00000036:651872 Stack: QSYS / QLESPI QLECRTTH 774 : LE_Create_Thread2__FP12crtth_parm_t
00000036:652088 Stack: QSYS / QP0WPTHR QP0WPTHR 1006 : pthread_create_part2
00000036:652304 Stack: QP0WTEST / TPZTSTK0 TPZTSTK0 2 : threadfunc
00000036:652512 Stack: QP0WTEST / TPZTSTK0 TPZTSTK0 1 : foo
00000036:652712 Stack: QP0WTEST / TPZTSTK0 TPZTSTK0 2 : bar
00000036:677456 Stack: QSYS / QP0SSRV1 QP0SLIB 1061 : sleep
00000036:700096 Stack: QSYS / QP0SSRV2 QP0SWAIT 248 : qp0swait__FP13qp0ssigwait_t
00000036:700216 Stack: Completed
00000036:700408 Exit with return code of 0
Press ENTER to end terminal session.
</pre>
<br>
<hr>
API introduced: V4R3
<hr>
<center>
<table cellpadding="2" cellspacing="2">
<tr align="center">
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
"unix.htm">UNIX-Type APIs</a> | <a href="aplist.htm">APIs by category</a></td>
</tr>
</table>
</center>
</body>
</html>