Debugging a runnig process with dbgeng - dbgeng

I've writen a simple program based on a sample of the wdk that scans the memory from a dump file.
Now, I'd like to do the same on the process while it's running and I'm facing several issues:
I don't know how to break the running process
when leaving my program, the debugee is closed whereas I called DetachProcess.
Thanks
void ApplyCommandLineArguments(void)
{
HRESULT Status;
// Install output callbacks so we get any output that the
// later calls produce.
if ((Status = g_Client->SetOutputCallbacks(&g_OutputCb)) != S_OK)
{
Exit(1, "SetOutputCallbacks failed, 0x%X\n", Status);
}
if (isDump())
{
// Everything's set up so open the dump file.
if ((Status = g_Client->OpenDumpFile(g_DumpFile)) != S_OK)
{
Exit(1, "OpenDumpFile failed, 0x%X\n", Status);
}
// Finish initialization by waiting for the event that
// caused the dump. This will return immediately as the
// dump file is considered to be at its event.
if ((Status = g_Control->WaitForEvent(DEBUG_WAIT_DEFAULT,
INFINITE)) != S_OK)
{
Exit(1, "WaitForEvent failed, 0x%X\n", Status);
}
}
else
{
if ((Status = g_Client->AttachProcess(0,GetPid(),0/*DEBUG_ATTACH_NONINVASIVE*/)) != S_OK)
{
Exit(1, "AttachProcess failed, 0x%X\n", Status);
}
}
// Everything is now initialized and we can make any
// queries we want.
}

Related

SSIS 2019 - Failed to load project files from storage object

I have upgraded SSIS package from SQL Server 2016 to SQL Server 2019. I am getting below error while calling host.CurrentScriptingEngine.LoadProjectFromStorage() as well as host.SaveScriptProject() from script task. It's not able to load it and save it. What needs to be done to make it work?
Code:
private void RecompileScriptSource()
{
IDTSComponentMetaData100 srcComp = m_Pipeline.ComponentMetaDataCollection[BASE_SCRIPT_SOURCE_COMPONENT];
// Get design time instance of script source
CManagedComponentWrapper scriptSourceWrapper = srcComp.Instantiate();
// Get script host & save
try
{
ScriptComponentHost host = (scriptSourceWrapper as IDTSManagedComponent100).InnerObject as ScriptComponentHost;
if (host == null)
{
throw new Exception("Failed to get access to the host object for the script component.");
}
log(host.ProjectTemplatePath+"-----"); //testing or debugging purpose
if (!host.LoadScriptFromComponent()) // This returns false
{
throw new Exception("Failed to load script information from component.");
}
VSTAComponentScriptingEngine engine = host.CurrentScriptingEngine;
if (engine.VstaHelper == null)
{
throw new Exception("Vsta 3.0 is not installed properly");
}
// Facing error here
if (!host.CurrentScriptingEngine.LoadProjectFromStorage())
{
throw new Exception("Failed to load project files from storage object");
}
if (!host.SaveScriptProject())
{
throw new Exception("Failed to save project");
}
else
{
log("Saved script project");
}
engine.DisposeVstaHelper();
}
finally
{
log("Finished saving (or compiling or whatever");
}
}

Node.js does not wait for the MySQL server sends the answer, and continues to work asynchronously

Print haphazardly and not wait for MySQL send a reply.
var mysql=require('mysql').createConnection({
host:'localhost',user:'root',password:'',database:'dbname',port:3306
});
mysql.connect(function(error){if(error){throw error;}else{console.log('MYSQL SERVER [OK]');}});
console.log('// INI //');
var sql='SELECT * FROM sys_users';
mysql.query(sql,function(error,rows){
if(!error){
for(i=0;i<rows.length;i++){
if(i<rows.length-1)
console.log(rows[i].username);
else console.log(rows[i].username);
}
}else console.log('Error');
});
console.log('// END //');
mysql.end();
would have to print:
MYSQL SERVER [OK]
// INI //
List item
// END //
but nevertheless printed:
// INI //
// END //
MYSQL SERVER [OK]
List item
That's the nature of Node.js - callbacks and async code processing.
If you want to run come code after the database response will be returned, place that code inside the callback:
mysql.query(sql,function(error,rows){
if (!error){
for(i=0;i<rows.length;i++){
if(i<rows.length-1)
console.log(rows[i].username);
else
console.log(rows[i].username);
}
} else {
console.log('Error');
}
/* Code to run. Move it to first `if`, if you want to run it only, when no error will occur. */
console.log('//END //');
});
mysql.end();

Server-Sent Event is not working- Browsers can not listen any events of Server-Sent Event

I am implementing of server-sent event(HTML5) in my project without using node.js, It is just simple webpage(another JSP page) call and i get response from it. But when i get response from it but none of method/function(onopen,onmessage or onerror) is execute...
Client Code:
if (!!window.EventSource) {
var source=new EventSource("kitAvailCall.jsp");
source.onopen = function(){
alert("Kit is not available");
source.close();
};
source.onmessage=function(event){
console.log(event.data);
alert("Kit is not available");
}
source.onerror =function(){
console.log("EventSOurce: Getting error call");
alert("Kit is not available");
}
}
Server-side code:
try{
while(true) {
Thread.sleep(15000);
String IpAddress = (String) session.getAttribute("IPName");
boolean bool;
if(IpAddress != null && ((new Date()).getTime() - session.getLastAccessedTime())/1000 > 28){
bool = sample.pingToKit((String) session.getAttribute("IPName"));
System.out.println("Long polling request: "+bool);
//if bool is false then i want to quit loop and back to browser
if(bool == false){
response.setHeader("Content-Type","text/event-stream");
response.setHeader("Cache-Control", "no-cache");
out.print("data: " + bool);
out.flush();
break;
}
}
}
}catch(Exception e){
System.out.println("Going bad CONN:"+ e);
}
I don't know much of java, but i could conjecture that you might be listening to the same controller/jsp servlet(whatever routes data in java) which you made to send as streaming.
Listen on a page other than kitavailcall.jsp. This script is meant only for streaming, use another view/html page other than kitavailcall.jsp
The thing you have to understand is, SSE is a concurrent process, you create another page and run on that page with the javascript(client code) included in that page. And your server should support multi-threading as well.

Calling Email OnError from ScriptTask of SSIS

I have a simple SSIS package with a single script task on it. I have an OnError event with a Send Mail task.
All i'm doing is testing to see if i can send an email when i detect an error withing my script.
However the variable i use to hold the Error message for my email causes an error.
"A deadlock was detected while trying to lock variable "User::errMsg" for read access. "
Here is the very simple script
public void Main()
{
try
{
int x = 2;
if (x ==2)
{
throw new Exception("The number was 2");
}
Dts.TaskResult = (int)ScriptResults.Success;
}
catch(Exception e)
{
Dts.Variables["errMsg"].Value = e.Message;
Dts.Events.FireError(-1, "here", "my error", "", 0);
Dts.TaskResult = (int)ScriptResults.Failure;
}
How can i pass a message to my send email when an error occurs in my script task ?
SSIS variables are locked and are relased only in its Post Execute event .In your case errMsg variable gets locked by the script task and the same time the variable is accessed in On Error event by the SendMail component creating a deadlock situation .You need to specifically unlock the variable before it is accessed by other components during its execution phase.
Try this :-
catch (Exception e)
{
Variables lockedVariables = null;
Dts.VariableDispenser.LockOneForWrite("errMsg", ref lockedVariables);
lockedVariables["errMsg"].Value = e.Message;
lockedVariables.Unlock();
Dts.Events.FireError(-1, "here", "my error", "", 0);
Dts.TaskResult = (int)ScriptResults.Failure;
}
This will ensure that before the error occurs ,the variable is unlocked and can be accessed in execution events such as On Error or OnExecStatusChanged.
More on how to handle these type of deadlocks is explained by Todd McDermid in his blog

How to pass errors conditions

In web app development I would like a consistent way to catch and report error conditions. For example, a database update routine may detect a variety of error conditions and ideally I would like the application to capture them and report gracefully. The code below din't work because retdiag is undefined when error is thrown...
function saveData(app,e) {
var db ;
var retdiag = "";
var lock = LockService.getPublicLock();
lock.waitLock(30000);
try {
// e.parameters has all the data fields from form
// re obtain the data to be updated
db = databaseLib.getDb();
var result = db.query({table: 'serviceUser',"idx":e.parameter.id});
if (result.getSize() !== 1) {
throw ("DB error - service user " + e.parameter.id);
}
//should be one & only one
retdiag = 'Save Data Finished Ok';
}
catch (ex) {
retdiag= ex.message // undefined!
}
finally {
lock.releaseLock();
return retdiag;
}
}
Is there a good or best practice for this is GAS?
To have a full error object, with message and stacktrace you have to build one, and not just throw a string. e.g. throw new Error("DB error ...");
Now, a more "consistent" way I usually implement is to wrap all my client-side calls into a function that will treat any errors for me. e.g.
function wrapper_(f,args) {
try {
return f.apply(this,args);
} catch(err) {
;//log error here or send an email to yourself, etc
throw err.message || err; //re-throw the message, so the client-side knows an error happend
}
}
//real client side called functions get wrapped like this (just examples)
function fileSelected(file,type) { return wrapper_(fileSelected_,[file,type]); }
function loadSettings(id) { return wrapper_(loadSettings_,[id]); }
function fileSelected_(file,type) {
; //do your thing
}
function loadSettings_(id) {
; //just examples
throw new Error("DB error ...");
}