Skip to content

Commit

Permalink
Merge pull request #1806 from WalterBright/fix9788
Browse files Browse the repository at this point in the history
fix Issue 9788 - -profile doesn't work if exceptions are thrown in the r...
  • Loading branch information
andralex committed Mar 31, 2013
2 parents 89d3caf + a1dd1ab commit cfb5842
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/func.c
Expand Up @@ -1650,7 +1650,7 @@ void FuncDeclaration::semantic3(Scope *sc)
{
if (!global.params.is64bit &&
global.params.isWindows &&
!isStatic() && !fbody->usesEH())
!isStatic() && !fbody->usesEH() && !global.params.trace)
{
/* The back end uses the "jmonitor" hack for syncing;
* no need to do the sync at this level.
Expand Down
55 changes: 35 additions & 20 deletions src/glue.c
Expand Up @@ -913,27 +913,42 @@ void FuncDeclaration::toObjFile(int multiobj)
bx.module = getModule();
irs.blx = &bx;

/* If profiling, insert call to the profiler here.
* _c_trace_pro(char* funcname);
/* Doing this in semantic3() caused all kinds of problems:
* 1. couldn't reliably get the final mangling of the function name due to fwd refs
* 2. impact on function inlining
* 3. what to do when writing out .di files, or other pretty printing
*/
if (global.params.trace)
{
dt_t *dt = NULL;

char *id = s->Sident;
size_t len = strlen(id);
dtnbytes(&dt, len + 1, id);

Symbol *sfuncname = symbol_generate(SCstatic,type_fake(TYchar));
sfuncname->Sdt = dt;
sfuncname->Sfl = FLdata;
out_readonly(sfuncname);
outdata(sfuncname);
elem *efuncname = el_ptr(sfuncname);

elem *eparam = el_params(efuncname, el_long(TYsize_t, len), NULL);
elem *e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_TRACE_CPRO]), eparam);
block_appendexp(bx.curblock, e);
{ /* Wrap the entire function body in:
* trace_pro("funcname");
* try
* body;
* finally
* _c_trace_epi();
*/
StringExp *se = new StringExp(0, s->Sident);
se->type = new TypeDArray(Type::tchar->invariantOf());
se->type = se->type->semantic(0, NULL);
Expressions *exps = new Expressions();
exps->push(se);
FuncDeclaration *fdpro = FuncDeclaration::genCfunc(Type::tvoid, "trace_pro");
Expression *ec = new VarExp(0, fdpro);
Expression *e = new CallExp(0, ec, exps);
e->type = Type::tvoid;
Statement *sp = new ExpStatement(loc, e);

FuncDeclaration *fdepi = FuncDeclaration::genCfunc(Type::tvoid, "_c_trace_epi");
ec = new VarExp(0, fdepi);
e = new CallExp(0, ec);
e->type = Type::tvoid;
Statement *sf = new ExpStatement(loc, e);

Statement *stf;
if (sbody->blockExit(tf->isnothrow) == BEfallthru)
stf = new CompoundStatement(0, sbody, sf);
else
stf = new TryFinallyStatement(0, sbody, sf);
sbody = new CompoundStatement(0, sp, stf);
}

#if DMDV2
Expand All @@ -942,7 +957,7 @@ void FuncDeclaration::toObjFile(int multiobj)

#if TARGET_WINDOS
if (func->isSynchronized() && cd && config.flags2 & CFG2seh &&
!func->isStatic() && !sbody->usesEH())
!func->isStatic() && !sbody->usesEH() && !global.params.trace)
{
/* The "jmonitor" hack uses an optimized exception handling frame
* which is a little shorter than the more general EH frame.
Expand Down
2 changes: 1 addition & 1 deletion src/msc.c
Expand Up @@ -88,7 +88,7 @@ void backend_init()
out_config_init(
params->is64bit ? 64 : 32,
exe,
params->trace,
false, //params->trace,
params->nofloat,
params->verbose,
params->optimize,
Expand Down

0 comments on commit cfb5842

Please sign in to comment.