View executed sql statements from a crash dump - sql

How can I view executed SQL stored procedures from a memory crash dump of a C# .net application?

The information you want might not be available any more. The objects representing connections, queries and results may already have been garbage collected.
If you know the name of the class that is used for a query, you can use windbg, load the sos extension and use the !dumpheap -type <classname> command to find those objects. Then use !do <address> to display the details of such an object. This might reveal the statement behind it.
If you're looking for a specific query, download the netext extension. It comes with the !wfrom command which allows you to select objects from the .NET heap based on criteria that you define.

This question has no trivial answer and many experienced debuggers had to face this issue one way of another. Getting the information for a single SQL command is tedious, but straightforward. For many it is difficult. I was helping a colleague on a situation like this and put together this solution. It requires NetExt (download the zip file): https://github.com/rodneyviana/netext/tree/master/Binaries
0:067> !windex
Starting indexing at 14:18:54 PM
1000000 objects...
2000000 objects...
3000000 objects...
4000000 objects...
Indexing finished at 14:19:04 PM
399,314,598 Bytes in 4,049,972 Objects
Index took 00:00:10
0:067> .foreach ({$addr} {!wfrom -type *.sqlcommand -nospace -nofield where (_commandType == 4) select _parameters._items._items}) { r #$t1= {$addr} ;!wfrom -type *.sqlcommand -nofield -nospace where (_parameters._items._items==$dbgeval("#$t1")) "\n", _commandText," [",$addr(),"]\n========================"; !wfrom -nospace -nofield -array {$addr} _parameterName,"=",$pp(_value) }
dbo.proc_getSiteIdOfHostHeaderSite [00000001011FCD90]
========================
#RETURN_VALUE=0n0
#HostHeader=sp.contoso.com
#RequestGuid={00000000-0000-0000-0000-000000000000}
proc_GetTpWebMetaDataAndListMetaData [0000000101D98DA0]
========================
#RETURN_VALUE=0n0
#WebSiteId={2815591d-55c8-4caf-842c-101d8807cb2a}
#WebId=NULL
#Url=
#ListId=NULL
#ViewId=NULL
#RunUrlToWebUrl=1
#DGCacheVersion=0n2
#SystemId=69 3a 30 29 2e 77 7c 73 2d 31 2d 35 2d 32 31 2d 31 33 38 35 31 37 34 39 39 32 2d 39 37 39 39 35 i:0).w|s-1-5-21-1385174992-97995 (...more...)
#MetadataFlags=0n18
#ThresholdScopeCount=0n5000
#CurrentFolderUrl=NULL
#RequestGuid={a00a0b30-1fcc-44d6-8346-ec20f8c49304}
proc_EnumLists [000000010236EDF0]
========================
#RETURN_VALUE=0n0
#WebId={a0a099b2-6023-4877-a7c1-378ec68df759}
#Collation=Latin1_General_CI_AS
#BaseType=NULL
#BaseType2=NULL
#BaseType3=NULL
#BaseType4=NULL
#ServerTemplate=NULL
#FMobileDefaultViewUrl=NULL
#FRootFolder=NULL
#ListFlags=0n-1
#FAclInfo=0n1
#Scopes=NULL
#FRecycleBinInfo=NULL
#UserId=NULL
#FGP=NULL
#RequestGuid={a00a0b30-1fcc-44d6-8346-ec20f8c49304}
(...)

Related

SAS : Data does not exist even tough they do

I am new in SAS environment. Maybe this is a stupid question but I cannot figure it out.
LIBNAME CODY '/folders/myfolders/Cody';
data In_Both
Missing_Name(drop = Name);
merge purchase(in=In_Purch)
inventory(in=In_Invent);
by Model;
if In_Purch and In_Invent then output In_Both;
else if In_Invent and not In_Purch then output Missing_Name;
run;
This is the error I receive
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 LIBNAME CODY '/folders/myfolders/Cody';
NOTE: Libref CODY was successfully assigned as follows:
Engine: V9
Physical Name: /folders/myfolders/Cody
74
75 data In_Both
76 Missing_Name(drop = Name);
77 merge purchase(in=In_Purch)
78 inventory(in=In_Invent);
ERROR: File WORK.PURCHASE.DATA does not exist.
ERROR: File WORK.INVENTORY.DATA does not exist.
79 by Model;
80 if In_Purch and In_Invent then output In_Both;
81 else if In_Invent and not In_Purch then output Missing_Name;
82 run;
It seems that SAS cannot find the files even though they exists.
I'm using SAS university Edition.
The code should give me 2 datasets, one with the merged observation and another one with the unmerged observations.
Is there a specific way to load the datasets I need?
The two datasets are in format sas7bdat
Thanks everyone for the help!
Change the merge statement in your code to
merge
CODY.purchase(in=In_Purch)
CODY.inventory(in=In_Invent)
;
The log is telling you the step is looking for tables in the WORK library, not CODY
Let's look at the original code.
data In_Both Missing_Name(drop = Name);
merge
purchase(in=In_Purch)
inventory(in=In_Invent)
;
by Model;
if In_Purch and In_Invent then output In_Both;
else
if In_Invent and not In_Purch then output Missing_Name;
run;
The data set names purchase and inventory in the merge do not include a <libref>.. When a libref is not present, SAS will default to the WORK folder.
The error messages in the log clearly tells you the problem
ERROR: File WORK.PURCHASE.DATA does not exist.
ERROR: File WORK.INVENTORY.DATA does not exist.
You can see the step was looking for WORK.PURCHASE and WORK.INVENTORY and did not find them (because they are in the CODY library)
Change the data sets being merged to include the appropriate library, thus you want CODY.purchase and CODY.inventory

STM32 Atollic TrueSTUDIO - Graphical view of the Memory

I'm using Atollic TrueSTUDIO for STM32 as an Eclipse Based IDE to perform Digital Signal Processing on audio signal. I'm looking for a way to plot an array (16 bits audio samples) from RAM memory. For the moment I'm using :
The memory View
The SWV real time data time line
None of this tools are powerful to analyse signal on an array, and it doesn't have to be on real time : Just ploting an array after reaching a breakpoint.
Is there an Eclipse Plugin or some other ways to do this ?
I'm considering to export the RAM memory and in a file and plot it in Matlab, but it seems really inapropriate for such a simple thing.
Thanks for any advices
In Atollic, you can easily attach gdb commands to breakpoints. Doing this, allows you to automaticly dump any variables. Additionally, you can execute an external programm once afterwards, to plot the content of the dumped variable.
To do so, goto breakpoint properties and create a new action. Select "Debugger Command Action" and use dump binary value x.bin x to dump variable x to file x.bin
You can also start a python script from the breakpoint to plot the data.
Use an additonal "External Tool Action" and select your python location. Make sure to select your current Working Dictonary. Use the arguments to pass the full path of the python file. The following file will import a float array and plot it.
import struct
import numpy as np
import matplotlib.pyplot as plt
import os
def readBinaryDump(filename):
result = []
N=8
with open(filename,'rb') as f:
while(True):
b = f.read(4*N);
if len(b) ==0:
break
fn = "f"*N
result.append(struct.unpack(fn,b))
result = np.array(result)
return result.ravel()
plt.plot(readBinaryDump("x.bin"))
Don't forget to add the actions to the current breakpoint. Now once the breakpoint is reached, the variable should be dumped and plotted automaticly.
While it's surprising nothing could be embeded in Atollic/Eclipse, I followed the idea of writing an specific application. Here are the steps I used :
Dump Memory :
Debug your software
Stop on a BreakPoint
View > Memory > Export Button > Format : "Plain Text"
The file representing a sine wawe looks like this :
00 00 3E 00 7D 00 BC 00 FB 00 39 01 78 01
B7 01 F6 01 34 02 73 02 B2 02 F0 02 2F 03
You should read these int16 samples like this :
1. 0x0000
2. 0x003E
3. 0x007D
4. etc...
Write this Matlab script :
fileID = fopen('your_file','r');
samples = textscan(fileID,'%s')
fclose(fileID);
samples = samples{1};
words = strcat(samples(2:2:end,1), samples(1:2:end,1));
values = typecast(uint16(hex2dec(words)),'int16');
plot(values) ;
The sinus wave plotted in Matlab
While there aren't any Eclipse plugins that would do what you're asking for that I'm personally aware of, there's STM Studio whose main purpose is displaying variables in real-time. It parses your ELF file to get the available variables, so the effort to at least give it a try should be minimal.
It's available here: https://www.st.com/en/development-tools/stm-studio-stm32.html
ST-Link is required to run it.
Write the simple app in C#. Use semi hosting to dump the memory to the text file. Open it and display.
Recently I had problem with MEMS-es and this was written in less than one hour. IMO (In My Opinion) it is easier to write program which will visualize the data instead of wasting hours or days searching for the ready made one:

COBOL capture arrow keystrokes

I'm completely new to COBOL, so as a learning excercise (and just for the sake of it) I'm trying to make a small console based game of connect 4. However I'm struggling to find a way of listening for and reading in keystrokes (for example using the arrow keys to move a piece left and right) without having to press enter after. So far the best solution I've found is to use Microfocus' Enhanced Accept/Display (Adis) which allows the use of the function keys in the manner I would like. I was wondering if there was something I may have missed, or a way of using Adis that would permit me the same sort of functionality with other keys than the function keys. The following program (shamelessly copied from https://www.microfocus.co.jp/manuals/SE/books/uisckb.htm) demonstrates the use of the function keys in the manner I would like:
1$set noosvs mf ans85
2**********************************************************
3* Copyright Micro Focus International 2000. All Rights *
4* Reserved. This demonstration program is provided for *
5* use by users of Micro Focus products and may be used, *
6* modified and distributed as part of your application *
8* provided that you properly acknowledge the copyright *
9* of Micro Focus in this material. *
9**********************************************************
10
11**********************************************************
12* *
13* FUNKEY.CBL *
14* *
15* This program demonstrates how to decode function *
16* keys using the x"af" call. *
17* *
18**********************************************************
19 special-names.
20 crt status is key-status.
21
22 working-storage section.
23 01 flag pic 9(2) comp-x value 1.
24 01 user-key-control.
25 05 enable-fn-keys pic 9(2) comp-x value 1.
26 05 filler pic x value "1".
27 05 first-user-key pic 9(2) comp-x value 1.
28 05 number-of-keys pic 9(2) comp-x value 10.
29
30 01 key-status.
31 05 key-type pic x.
32 05 key-code-1 pic 9(2) comp-x.
33 05 filler pic x.
34 01 any-data pic x.
35 01 key-code-1-display pic z9.
36
37 procedure division.
38 perform enable-keys
39 perform accept-function-key
40 perform tell-which-key-was-pressed
41 perform stop-run.
42
43 enable-keys.
44 call x"af" using flag user-key-control.
45
46 accept-function-key.
47 display spaces upon crt
48 display "Press a function key: F1 to F10" at 0505
49 accept any-data at 0540.
50
51 tell-which-key-was-pressed.
52 evaluate key-type
53 when 0 display "You pressed <Enter>" at 0705
54 when 1
55 move key-code-1 to key-code-1-display
56 display "You pressed function key" at 0705
57 display key-code-1-display at 0730
58 end-evaluate.
59
60 stop-run.
61 stop run.
It you are up for using a little non-conventional COBOL, the S-Lang library is the bee's knees when it comes to keyboard handling. No ADIS required, but with care the two can live peacefully together. Trying this example will require GNU Cobol 1.1 and libslang (by John E. Davis, jedsoft).
OCOBOL >>SOURCE FORMAT IS FIXED
*> ***************************************************************
*> Date: 20090503
*> License: Copyright 2009, Brian Tiffin
*> licensed for use under the GNU GPLv2
*> Purpose: Experimental S-Lang keyboard interface
*> Tectonics: cobc -x slangkey.cob -lslang
*> ***************************************************************
identification division.
program-id. slangkey.
data division.
working-storage section.
01 thekey usage binary-long unsigned.
01 thekm usage binary-long.
01 result usage binary-long.
*> exit handler address and priority (prio is IGNORED with OC1.1)
01 install-flag pic 9 comp-x value 0.
01 install-params.
02 exit-addr usage is procedure-pointer.
02 handler-prio pic 999 comp-x.
*> ***************************************************************
procedure division.
*> Initialize low and high level S-Lang terminal routines
call "SLtt_get_terminfo" end-call
call "SLkp_init" returning result end-call
if result equal -1
display "problem intializing S-Lang tty" end-display
stop run giving 1
end-if
call "SLang_init_tty" using
by value -1 *> abort char
by value -1 *> flow ctrl
by value 0 *> output processing
returning result
end-call
if result equal -1
display "problem intializing S-Lang tty" end-display
stop run giving 1
else
display "Keyboard in special mode" x"0d" end-display
end-if
*> install an exit handler to put terminal back
set exit-addr to entry "tty-reset"
call "CBL_EXIT_PROC" using
install-flag
install-params
returning result
end-call
if result not equal zero
display "error installing exit procedure" end-display
end-if
*> Not sure? Have SLang handle ^C or let GNU Cobol take over?
call "SLang_set_abort_signal" using by value 0 end-call
*> The demo. Fetch a key, then fetch a keycode. 4 times.
*> SLang terminals display newline as newline. Need explicit
*> CR to get a carriage return. Hence the x"0d".
*> Plus, output is buffered until line terminators.
display
"Tap a normal key, then tap a 'special' key, ie F1, 4 times"
x"0d"
end-display
perform 4 times
call "SLang_getkey" returning thekey end-call
display thekey space with no advancing end-display
call "SLkp_getkey" returning thekm end-call
display thekm x"0d" end-display
end-perform
*> Exit handler will take care of resetting terminal
goback.
*> ***************************************************************
*> Exit procedure to ensure terminal properly reset
*> ***************************************************************
entry "tty-reset".
call "SLang_reset_tty" end-call
display "exit proc reset the tty" end-display
goback.
end program slangkey.
A bit late to the party but:
Documentation for ADIS can be found at https://supportline.microfocus.com/Documentation/books/sx51/sx51indx.htm - look for "Character user interfaces", and specifically the section "Keyboard handling via ADIS". The paragraph "enable-function-keys" in your code enables the function keys from F1 to F10. What you need to do is change the function of the cursor keys, which are ADIS keys, and to do this you need
01 adis-key-control.
05 enable-adis-keys pic 9(2) comp-x value 1.
05 filler pic x value "2".
05 first-adis-key pic 9(2) comp-x value 3.
05 number-of-adis-keys pic 9(2) comp-x value 8.
Then add the line
call x"af" using flag adis-key-control.
to the paragraph enable-function-keys. This will allow you to capture cursor left, right, up, and down, plus Home, tab, backtab, and End.
I do not have Micro Focus COBOL, but a quick internet search seems to indicate that the example you chose introduces some confusion by using the term function-keys and show values received from pressing function-keys.
It may be that using the function-keys was the simplest for the example, because the key-value is 1 to 10, so needing no translation from key-value to key that you understand. It shows 3, you know it means F3.
The only clue in the example you show is 05 number-of-keys pic 9(2) comp-x val. If the number of keys used by the x'af' CALL is configurable, then it can changed, then, likely, keys themselves can be changed.
You ask about ADIS (Micro Focus's Extended ACCEPT and DISPLAY)? Yes. It is all within ADIS. All the cursor keys are part of the Standard Adis Key Functions.
If you run the example program and press the arrow keys instead of a function key, what happens?
I searched for micro focus user interface manual and found enough information to make it necessary to know which particular Micro Focus product you have.

Apache mod_speling falsely "correcting" URLs?

I've been tasked with moving an old dynamic website from a Windows server to Linux. The site was initially written with no regard to character case. Some filenames were all upper-case, some lower-case, and some mixed. This was never a problem in Windows, of course, but now we're moving to a case-sensitive file system.
A with a quick find/rename command (thanks to another tutorial) got the filenames to all lowercase.
However, many of the URL references in the code still point to these mixed-case filenames, so I enabled mod_speling to overcome this issue. It seems to work OK for the most part, with the exception of one page: I have a file name haematobium.html, which, everytime a link points to .../haematobium.html, it gets rewritten as .../hæmatobium.html in the browser.
I don't know how this strange character made its way into the filename in the first place, but I've corrected the code in the HTML document to now link to haematobium.html, then renamed the haematobium.html file itself to match.
When requesting .../haematobium.html in Chrome, it "corrects" to .../hæmatobium.html in the address bar, and shows an error saying "The requested URL .../hæmatobium.html was not found on this server."
In IE9, I'm promted for the login (this is a .htaccess protected page), I enter it, and then if forwards the URL to .../h%C3%A6matobium.html, which again doesn't load.
In my frustration I even copied haematobium.html to both hæmatobium.html and hæmatobium.html, still, none of the three pages actually load.
So my question: I read somewhere that mod_speling tries to "learn" misspelled URLs. Does it actually rename files (is that where the odd character might have come from)? Does it keep a cache of what's been called for, and what it was forwarded to (a cache I could clear)?
PS. there are also many mixed-case references to MySQL database tables and fields, but that's a whole 'nother nightmare.
[Cannot comment yet, therefore answering.]
Your question doesn't make it entirely clear which of the two names (two characters ae [ASCII], or one ligature character æ [Unicode]) for haematobium.html actually exists in your Apache's file system.
Try the following in your shell:
$ echo -n h*matobium.html | hd
The output should be either one of the following two alternatives. This is ASCII, with 61 and 65 for a and e, respectively:
00000000 68 61 65 6d 61 74 6f 62 69 75 6d 2e 68 74 6d 6c |haematobium.html|
00000010
And this is Unicode, with c3 a6 for the single character æ:
00000000 68 c3 a6 6d 61 74 6f 62 69 75 6d 2e 68 74 6d 6c |h..matobium.html|
00000010
I would recommend using the ASCII version, it makes life considerably easier.
Now to your actual question. mod_speling does neither "learn", nor rename or cache its data. The caching is either done by your browsers, or by proxies in between your browsers and the server.
It's actually best practice to test these cases with command line tools like wget or curl, which should be already available or easily installable on any Linux.
Use wget -S or curl -i to actually see the response headers sent by your web server.

How to save and retrieve string with accents in redis?

I do not manage to set and retrieve string with accents in my redis db.
Chars with accents are encoded, how can I retrieve them back as they where set ?
redis> set test téléphone
OK
redis> get test
"t\xc3\xa9l\xc3\xa9phone"
I know this has already been asked
(http://stackoverflow.com/questions/6731450/redis-problem-with-accents-utf-8-encoding) but there is no detailed answer.
The Redis server itself stores all data as a binary objects, so it is not dependent on the encoding. The server will just store what is sent by the client (including UTF-8 chars).
Here are a few experiments:
$ echo téléphone | hexdump -C
00000000 74 c3 a9 6c c3 a9 70 68 6f 6e 65 0a |t..l..phone.|
c3a9 is the representation of the 'é' char.
$ redis-cli
> set t téléphone
OK
> get t
"t\xc3\xa9l\xc3\xa9phone"
Actually the data is correctly stored in the Redis server. However, when it is launched in a terminal, the Redis client interprets the output and applies the sdscatrepr function to transform non printable chars (whose definition is locale dependent, and may be broken for multibyte chars anyway).
A simple workaround is to launch redis-cli with the 'raw' option:
$ redis-cli --raw
> get t
téléphone
Your own application will probably use one of the client libraries rather than redis-cli, so it should not be a problem in practice.