RZ_IPI bool rz_analysis_var_global_list_show(RzAnalysis *analysis, RzCmdStateOutput *state, RZ_NULLABLE const char *name) {
	rz_return_val_if_fail(analysis && state, false);
	RzList *global_vars = NULL;
	RzAnalysisVarGlobal *glob = NULL;
	if (name) {
		global_vars = rz_list_new();
		if (!global_vars) {
			return false;
		}
		glob = rz_analysis_var_global_get_byname(analysis, name);
		if (!glob) {
			RZ_LOG_ERROR("Global variable '%s' does not exist!\n", name);
			rz_list_free(global_vars);
			return false;
		}
		rz_list_append(global_vars, glob);
	} else {
		global_vars = rz_analysis_var_global_get_all(analysis);
	}

	RzListIter *it = NULL;
	char *var_type = NULL;
	bool json = state->mode == RZ_OUTPUT_MODE_JSON;
	PJ *pj = json ? state->d.pj : NULL;

	rz_cmd_state_output_array_start(state);
	if (!global_vars) {
		rz_cmd_state_output_array_end(state);
		return false;
	}
	rz_list_foreach (global_vars, it, glob) {
		var_type = rz_type_as_string(analysis->typedb, glob->type);
		if (!var_type) {
			continue;
		}
		switch (state->mode) {
		case RZ_OUTPUT_MODE_STANDARD:
			rz_cons_printf("global %s %s @ 0x%" PFMT64x "\n",
				var_type, glob->name, glob->addr);
			break;
		case RZ_OUTPUT_MODE_JSON:
			pj_o(pj);
			pj_ks(pj, "name", glob->name);
			pj_ks(pj, "type", var_type);
			char addr[32];
			rz_strf(addr, "0x%" PFMT64x, glob->addr);
			pj_ks(pj, "addr", addr);
			pj_end(pj);
			break;
		default:
			break;
		}
		free(var_type);
	}
	rz_cmd_state_output_array_end(state);
	rz_list_free(global_vars);
	return true;
}
RZ_IPI bool rz_analysis_var_global_list_show(RzAnalysis *analysis, RzCmdStateOutput *state, RZ_NULLABLE const char *name) {
	rz_return_val_if_fail(analysis && state, false);
	RzList *global_vars = NULL;
	RzAnalysisVarGlobal *glob = NULL;
	if (name) {
		global_vars = rz_list_new();
		if (!global_vars) {
			return false;
		}
		glob = rz_analysis_var_global_get_byname(analysis, name);
		if (!glob) {
			RZ_LOG_ERROR("Global variable '%s' does not exist!\n", name);
			rz_list_free(global_vars);
			return false;
		}
		rz_list_append(global_vars, glob);
	} else {
		global_vars = rz_analysis_var_global_get_all(analysis);
	}

	RzListIter *it = NULL;
	char *var_type = NULL;
	bool json = state->mode == RZ_OUTPUT_MODE_JSON;
	PJ *pj = json ? state->d.pj : NULL;

	rz_cmd_state_output_array_start(state);
	if (!global_vars) {
		rz_cmd_state_output_array_end(state);
		return false;
	}
	rz_list_foreach (global_vars, it, glob) {
		var_type = rz_type_as_string(analysis->typedb, glob->type);
		if (!var_type) {
			continue;
		}
		switch (state->mode) {
		case RZ_OUTPUT_MODE_STANDARD:
			rz_cons_printf("global %s %s @ 0x%" PFMT64x "\n",
				var_type, glob->name, glob->addr);
			break;
		case RZ_OUTPUT_MODE_JSON:
			pj_o(pj);
			pj_ks(pj, "name", glob->name);
			pj_ks(pj, "type", var_type);
			char addr[32];
			rz_strf(addr, "0x%" PFMT64x, glob->addr);
			pj_ks(pj, "addr", addr);
			pj_end(pj);
			break;
		default:
			break;
		}
		free(var_type);
	}
	rz_cmd_state_output_array_end(state);
	rz_list_free(global_vars);
	return true;
}