Bug 1420355 - Don't initialize DMD if the DMD environment variable is not given. r=njn

This makes things slightly more inconvenient (having to set two
environment variables instead of one for the simplest case) until a few
patches down the line, when DMD is statically linked, at which point it
will get down to one environment variable every time.

--HG--
extra : rebase_source : 08dc3c05318b572ae1026227d0369fa8bf21b20f
This commit is contained in:
Mike Hommey 2017-11-28 08:10:07 +09:00
Родитель 7c59f18de8
Коммит 1e631092c5
10 изменённых файлов: 31 добавлений и 21 удалений

Просмотреть файл

@ -1256,7 +1256,7 @@ FreeCallback(void* aPtr, Thread* aT, DeadBlock* aDeadBlock)
// malloc/free interception
//---------------------------------------------------------------------------
static void Init(malloc_table_t* aMallocTable);
static bool Init(malloc_table_t* aMallocTable);
} // namespace dmd
} // namespace mozilla
@ -1368,11 +1368,12 @@ replace_free(void* aPtr)
void
replace_init(malloc_table_t* aMallocTable, ReplaceMallocBridge** aBridge)
{
mozilla::dmd::Init(aMallocTable);
if (mozilla::dmd::Init(aMallocTable)) {
#define MALLOC_FUNCS MALLOC_FUNCS_MALLOC_BASE
#define MALLOC_DECL(name, ...) aMallocTable->name = replace_ ## name;
#include "malloc_decls.h"
*aBridge = mozilla::dmd::gDMDBridge;
*aBridge = mozilla::dmd::gDMDBridge;
}
}
namespace mozilla {
@ -1439,9 +1440,6 @@ Options::Options(const char* aDMDEnvVar)
, mStacks(Stacks::Partial)
, mShowDumpStats(false)
{
// It's no longer necessary to set the DMD env var to "1" if you want default
// options (you can leave it undefined) but we still accept "1" for
// backwards compatibility.
char* e = mDMDEnvVar;
if (e && strcmp(e, "1") != 0) {
bool isEnd = false;
@ -1551,10 +1549,21 @@ postfork()
// have run. For this reason, non-scalar globals such as gStateLock and
// gStackTraceTable are allocated dynamically (so we can guarantee their
// construction in this function) rather than statically.
static void
static bool
Init(malloc_table_t* aMallocTable)
{
// DMD is controlled by the |DMD| environment variable.
const char* e = getenv("DMD");
if (!e) {
return false;
}
// Initialize the function table first, because StatusMsg uses
// InfallibleAllocPolicy::malloc_, which uses it.
gMallocTable = *aMallocTable;
StatusMsg("$DMD = '%s'\n", e);
gDMDBridge = InfallibleAllocPolicy::new_<DMDBridge>();
#ifndef XP_WIN
@ -1566,16 +1575,6 @@ Init(malloc_table_t* aMallocTable)
// system malloc a chance to insert its own atfork handler.
pthread_atfork(prefork, postfork, postfork);
#endif
// DMD is controlled by the |DMD| environment variable.
const char* e = getenv("DMD");
if (e) {
StatusMsg("$DMD = '%s'\n", e);
} else {
StatusMsg("$DMD is undefined\n");
}
// Parse $DMD env var.
gOptions = InfallibleAllocPolicy::new_<Options>(e);
@ -1604,6 +1603,7 @@ Init(malloc_table_t* aMallocTable)
MOZ_ALWAYS_TRUE(gDeadBlockTable->init(tableSize));
}
return true;
}
//---------------------------------------------------------------------------

Просмотреть файл

@ -7,7 +7,7 @@ Invocation 1 {
}
Invocation 2 {
$DMD is undefined
$DMD = '1'
Mode = 'dark-matter'
}

Просмотреть файл

@ -1,7 +1,7 @@
{
"version": 5,
"invocation": {
"dmdEnvVar": null,
"dmdEnvVar": "1",
"mode": "dark-matter"
},
"blockList": [

Просмотреть файл

@ -2,7 +2,7 @@
# dmd.py --filter-stacks-for-testing -o script-ignore-alloc-fns-actual.txt --ignore-alloc-fns script-ignore-alloc-fns.json
Invocation {
$DMD is undefined
$DMD = '1'
Mode = 'dark-matter'
}

Просмотреть файл

@ -1,7 +1,7 @@
{
"version": 5,
"invocation": {
"dmdEnvVar": null,
"dmdEnvVar": "1",
"mode": "dark-matter"
},
"blockList": [

Просмотреть файл

@ -136,6 +136,7 @@ function run_test() {
// in-place (to fix stacks) when it runs dmd.py, and that's not safe to do
// asynchronously.
gEnv.set('DMD', '1');
gEnv.set(gEnv.get("DMD_PRELOAD_VAR"), gEnv.get("DMD_PRELOAD_VALUE"));
runProcess(gDmdTestFile, []);

Просмотреть файл

@ -945,6 +945,8 @@ class RunProgram(MachCommandBase):
if dmd_params:
env_vars[arch]["DMD"] = " ".join(dmd_params)
else:
env_vars[arch]["DMD"] = "1"
extra_env.update(env_vars.get(arch, {}))

Просмотреть файл

@ -170,6 +170,8 @@ class MachCommands(MachCommandBase):
arch = self.substs['OS_ARCH']
for k, v in env_vars[arch].iteritems():
os.environ[k] = v
if 'DMD' not in os.environ:
os.environ['DMD'] = '1'
# Also add the bin dir to the python path so we can use dmd.py
if bin_dir not in sys.path:

Просмотреть файл

@ -1634,6 +1634,9 @@ toolbar#nav-bar {
if options.headless:
browserEnv["MOZ_HEADLESS"] = '1'
if options.dmd:
browserEnv["DMD"] = os.environ.get('DMD', '1')
# These variables are necessary for correct application startup; change
# via the commandline at your own risk.
browserEnv["XPCOM_DEBUG_BREAK"] = "stack"

Просмотреть файл

@ -280,6 +280,8 @@ class MochiRemote(MochitestDesktop):
browserEnv["MOZ_LOG_FILE"] = os.path.join(
self.remoteMozLog,
self.mozLogName)
if options.dmd:
browserEnv['DMD'] = '1'
return browserEnv
def runApp(self, *args, **kwargs):