Question
· Nov 9, 2016

How to debug a CSP page

I'm trying to debug a CSP page but I'm not able to set up a breakpoint into <script> tag.

Is it possible to setup on CSP files? Am I forgeting something?

 

PS:

this is the tag

<script language="Cache" method="OnPreHTTP" arguments="" returntype="%Boolean">

Discussion (5)0
Log in or sign up to continue

Hi David,
you can actually debug a csp page with the studio debugger. However, this requires a bit more preparation, as you need to identify the csp server process running your page, which is not always straightforward.

An easier approach would be to use the command line debugger in combination with the CSP shell.

SAMPLES>ZBREAK zListFiles+1^csp.menu.1

SAMPLES>d $SYSTEM.CSP.Shell()
CSP Shell

Command shell for debugging CSP pages. It looks and acts like a Cache programmer prompt, but you can use the GET or HEAD command to fetch a CSP page. You can set breakpoints, step into the code etc. You may pass query parameters to the page as well, eg.:CSP>>> GET /csp/samples/request.csp?A=1&B=2

The output you see is what would be sent to the browser, including any HTTP headers. You can also interact with the session, request and response objects via the special variables %session, %request and %response.

CSP:SAMPLES>>> get /csp/samples/menu.csp
 200 OK
Content-Type: text/html; charset=utf-8
Set-Cookie: CSPSESSIONID-UP-csp-samples-=5864              5864; path=/csp/samples/;  httpOnly;
Cache-Control: no-cache
Date: Wed, 09 Nov 2016 17:49:45 GMT
Expires: Thu, 29 Oct 1998 17:04:19 GMT
Pragma: no-cache

<!-- Copyright (c) 2001 InterSystems Inc. ALL RIGHTS RESERVED. -->

<html>
<head>
<title>CSP Samples Menu</title>
<style type="text/css">
        body { color: black; background: #CCCCFF; font-size: 12pt; font-family: Verdana,Arial,Helvetica,sans-serif; }
        .Small { font-size: 10pt;}
        .DarkRow { background: #DDDDDD; }
        .LightRow { background: #FFFFFF; }
</style>
</head>

<body bgcolor="#CCCCFF">

<!-- display standard sample template using a custom tag -->

<table bgcolor="#000088" cols="2" width="100%" border="1" cellpadding="3">
<tr>
<td width="50%">
<nobr><font face="Verdana,Arial,Helvetica,sans-serif" color="white" size="+3">
<b>&nbsp;CSP Samples Menu</b>
</font></nobr>
</td>
</tr>
</table>
<br>

<table width="100%">
<tr>
<td width="66%"><font face="Verdana,Arial,Helvetica,sans-serif">
This page displays a list of available CSP pages within the same
directory.<br/>
Click this link to see a demonstration of the the <a href="ZENDemo.Home.cls">Zen Web Development Framework</a>.

</font></td>
<td align="right"><font face="Verdana,Arial,Helvetica,sans-serif"><a href="menu.csp">Samples Menu</a></font></td>
<td align="right"><font face="Verdana,Arial,Helvetica,sans-serif"><a href="showsource.csp?PAGE=/csp/samples/menu.csp">Source</a></font></td>
</tr>
</table>


   New file,rs,dir,menupath,subdir,list,page,description,url
   ^
<BREAK>zListFiles+2^csp.menu.1
SAMPLES 15d6>

In this example I am setting the breakpoint to

ZB zListFiles+1^csp.menu.1

and then request the menu page within the CSP shell:

SAMPLES>d $SYSTEM.CSP.Shell()
CSP Shell

Command shell for debugging CSP pages. It looks and acts like a Cache programmer prompt, but you can use the GET or HEAD command to fetch a CSP page. You can set breakpoints, step into the code etc. You may pass query parameters to the page as well, eg.:CSP>>> GET /csp/samples/request.csp?A=1&B=2

The output you see is what would be sent to the browser, including any HTTP headers. You can also interact with the session, request and response objects via the special variables %session, %request and %response.

CSP:SAMPLES>>> get /csp/samples/menu.csp

This drops us into the regular command line debugger.

I hope this helps.
-Fab

Here is some information about debugging CSP pages using Studio. I actually just taught this to students in class yesterday!

1. You can't set a breakpoint inside the ObjectScript on a CSP page (inside a <script> tag). But the workaround for this is to use the View > View Other Code and load the class definition that's generated from the CSP page. Then you can set breakpoints normally.

2. Once you've set breakpoints, you can set your CSP page as the Debugging Target, and launch it directly from Studio. The page runs in a special "debug mode". This means that the normal timeouts (typically 60 seconds) are suspended, so that the browser and the CSP Gateway will wait as long as necessary while you step through the code.

You can step through the code that is called when the page is first being built, and you can also step through code that is called via a hyperevent.

The only issue with stepping through the code is that Studio does not seem to be highlighting the current line as it normally does. I think this used to work fine, so I may bring this up with the developers. But a workaround for now is to use the "Call Stack" tab of the Watch Window. The top line of the call stack shows the label+offset of the current line. As you step, the top line is updated with the current label+offset. You can simply click the top line whenever you want and the Code Window will scroll to that line, also showing you the current values of the variables.