2 * Copyright (c) 2008, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * debug functions for the SAT solver
21 #include "solverdebug.h"
30 * create obsoletesmap from solver decisions
32 * for solvables in installed repo:
34 * p - one of the packages that obsolete us
36 * n - number of packages this package obsoletes
41 solver_create_decisions_obsoletesmap(Solver *solv)
43 Pool *pool = solv->pool;
44 Repo *installed = solv->installed;
45 Id p, *obsoletesmap = NULL;
49 obsoletesmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
52 for (i = 0; i < solv->decisionq.count; i++)
57 n = solv->decisionq.elements[i];
60 if (n == SYSTEMSOLVABLE)
62 s = pool->solvables + n;
63 if (s->repo == installed) /* obsoletes don't count for already installed packages */
65 noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n);
66 FOR_PROVIDES(p, pp, s->name)
68 Solvable *ps = pool->solvables + p;
69 if (noobs && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
71 if (!solv->implicitobsoleteusesprovides && s->name != ps->name)
73 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
80 for (i = 0; i < solv->decisionq.count; i++)
85 n = solv->decisionq.elements[i];
88 if (n == SYSTEMSOLVABLE)
90 s = pool->solvables + n;
91 if (s->repo == installed) /* obsoletes don't count for already installed packages */
95 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n))
97 obsp = s->repo->idarraydata + s->obsoletes;
98 while ((obs = *obsp++) != 0)
100 FOR_PROVIDES(p, pp, obs)
102 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
104 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
117 solver_printruleelement(Solver *solv, int type, Rule *r, Id v)
119 Pool *pool = solv->pool;
123 s = pool->solvables + -v;
124 POOL_DEBUG(type, " !%s [%d]", solvable2str(pool, s), -v);
128 s = pool->solvables + v;
129 POOL_DEBUG(type, " %s [%d]", solvable2str(pool, s), v);
134 POOL_DEBUG(type, " (w1)");
136 POOL_DEBUG(type, " (w2)");
138 if (solv->decisionmap[s - pool->solvables] > 0)
139 POOL_DEBUG(type, " Install.level%d", solv->decisionmap[s - pool->solvables]);
140 if (solv->decisionmap[s - pool->solvables] < 0)
141 POOL_DEBUG(type, " Conflict.level%d", -solv->decisionmap[s - pool->solvables]);
142 POOL_DEBUG(type, "\n");
151 solver_printrule(Solver *solv, int type, Rule *r)
153 Pool *pool = solv->pool;
157 if (r >= solv->rules && r < solv->rules + solv->nrules) /* r is a solver rule */
158 POOL_DEBUG(type, "Rule #%d:", (int)(r - solv->rules));
160 POOL_DEBUG(type, "Rule:"); /* r is any rule */
162 POOL_DEBUG(type, " (disabled)");
163 POOL_DEBUG(type, "\n");
164 d = r->d < 0 ? -r->d - 1 : r->d;
168 /* print direct literal */
174 /* binary rule --> print w2 as second literal */
178 /* every other which is in d */
179 v = solv->pool->whatprovidesdata[d + i - 1];
182 solver_printruleelement(solv, type, r, v);
184 POOL_DEBUG(type, " next rules: %d %d\n", r->n1, r->n2);
188 solver_printruleclass(Solver *solv, int type, Rule *r)
190 Pool *pool = solv->pool;
191 Id p = r - solv->rules;
193 if (p < solv->learntrules)
194 if (MAPTST(&solv->weakrulemap, p))
195 POOL_DEBUG(type, "WEAK ");
196 if (p >= solv->learntrules)
197 POOL_DEBUG(type, "LEARNT ");
198 else if (p >= solv->jobrules && p < solv->jobrules_end)
199 POOL_DEBUG(type, "JOB ");
200 else if (p >= solv->updaterules && p < solv->updaterules_end)
201 POOL_DEBUG(type, "UPDATE ");
202 else if (p >= solv->featurerules && p < solv->featurerules_end)
203 POOL_DEBUG(type, "FEATURE ");
204 solver_printrule(solv, type, r);
208 solver_printproblem(Solver *solv, Id v)
210 Pool *pool = solv->pool;
216 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, solv->rules + v);
220 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "JOB %d\n", v);
221 jp = solv->ruletojob.elements;
222 for (i = solv->jobrules, r = solv->rules + i; i < solv->learntrules; i++, r++, jp++)
225 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "- ");
226 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
228 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "ENDJOB\n");
233 solver_printwatches(Solver *solv, int type)
235 Pool *pool = solv->pool;
238 POOL_DEBUG(type, "Watches: \n");
239 for (counter = -(pool->nsolvables - 1); counter < pool->nsolvables; counter++)
240 POOL_DEBUG(type, " solvable [%d] -- rule [%d]\n", counter, solv->watches[counter + pool->nsolvables]);
248 solver_printdecisions(Solver *solv)
250 Pool *pool = solv->pool;
251 Repo *installed = solv->installed;
252 Id p, *obsoletesmap = solver_create_decisions_obsoletesmap(solv);
256 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
258 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n");
259 for (i = 0; i < solv->decisionq.count; i++)
261 p = solv->decisionq.elements[i];
262 solver_printruleelement(solv, SAT_DEBUG_SCHUBI, 0, p);
264 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n");
267 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
268 POOL_DEBUG(SAT_DEBUG_RESULT, "transaction:\n");
270 /* print solvables to be erased */
274 FOR_REPO_SOLVABLES(installed, p, s)
276 if (solv->decisionmap[p] >= 0)
280 POOL_DEBUG(SAT_DEBUG_RESULT, " erase %s\n", solvable2str(pool, s));
284 /* print solvables to be installed */
286 for (i = 0; i < solv->decisionq.count; i++)
289 p = solv->decisionq.elements[i];
292 if (p == SYSTEMSOLVABLE)
294 s = pool->solvables + p;
295 if (installed && s->repo == installed)
298 if (!obsoletesmap[p])
300 POOL_DEBUG(SAT_DEBUG_RESULT, " install %s", solvable2str(pool, s));
305 FOR_PROVIDES(xp, xpp, s->name)
307 Solvable *s2 = pool->solvables + xp;
308 if (s2->name != s->name)
310 if (evrcmp(pool, s->evr, s2->evr, EVRCMP_MATCH_RELEASE) < 0)
314 POOL_DEBUG(SAT_DEBUG_RESULT, " downgrade %s", solvable2str(pool, s));
316 POOL_DEBUG(SAT_DEBUG_RESULT, " upgrade %s", solvable2str(pool, s));
317 POOL_DEBUG(SAT_DEBUG_RESULT, " (obsoletes");
318 for (j = installed->start; j < installed->end; j++)
319 if (obsoletesmap[j] == p)
320 POOL_DEBUG(SAT_DEBUG_RESULT, " %s", solvable2str(pool, pool->solvables + j));
321 POOL_DEBUG(SAT_DEBUG_RESULT, ")");
323 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
325 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
327 sat_free(obsoletesmap);
329 if (solv->recommendations.count)
331 POOL_DEBUG(SAT_DEBUG_RESULT, "recommended packages:\n");
332 for (i = 0; i < solv->recommendations.count; i++)
334 s = pool->solvables + solv->recommendations.elements[i];
335 if (solv->decisionmap[solv->recommendations.elements[i]] > 0)
337 if (installed && s->repo == installed)
338 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (installed)\n", solvable2str(pool, s));
340 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (selected)\n", solvable2str(pool, s));
343 POOL_DEBUG(SAT_DEBUG_RESULT, " %s\n", solvable2str(pool, s));
345 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
348 if (solv->suggestions.count)
350 POOL_DEBUG(SAT_DEBUG_RESULT, "suggested packages:\n");
351 for (i = 0; i < solv->suggestions.count; i++)
353 s = pool->solvables + solv->suggestions.elements[i];
354 if (solv->decisionmap[solv->suggestions.elements[i]] > 0)
356 if (installed && s->repo == installed)
357 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (installed)\n", solvable2str(pool, s));
359 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (selected)\n", solvable2str(pool, s));
362 POOL_DEBUG(SAT_DEBUG_RESULT, " %s\n", solvable2str(pool, s));
364 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
366 if (solv->orphaned.count)
368 POOL_DEBUG(SAT_DEBUG_RESULT, "orphaned packages:\n");
369 for (i = 0; i < solv->orphaned.count; i++)
371 s = pool->solvables + solv->orphaned.elements[i];
372 if (solv->decisionmap[solv->orphaned.elements[i]] > 0)
373 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (kept)\n", solvable2str(pool, s));
375 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (erased)\n", solvable2str(pool, s));
377 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
382 solver_printprobleminfo(Solver *solv, Queue *job, Id problem)
384 Pool *pool = solv->pool;
386 Id dep, source, target;
389 probr = solver_findproblemrule(solv, problem);
390 switch (solver_problemruleinfo(solv, job, probr, &dep, &source, &target))
392 case SOLVER_PROBLEM_UPDATE_RULE:
393 s = pool_id2solvable(pool, source);
394 POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", solvable2str(pool, s));
396 case SOLVER_PROBLEM_JOB_RULE:
397 POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n");
399 case SOLVER_PROBLEM_RPM_RULE:
400 POOL_DEBUG(SAT_DEBUG_RESULT, "some dependency problem\n");
402 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
403 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep));
405 case SOLVER_PROBLEM_NOT_INSTALLABLE:
406 s = pool_id2solvable(pool, source);
407 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s is not installable\n", solvable2str(pool, s));
409 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
410 s = pool_id2solvable(pool, source);
411 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides %s needed by %s\n", dep2str(pool, dep), solvable2str(pool, s));
413 case SOLVER_PROBLEM_SAME_NAME:
414 s = pool_id2solvable(pool, source);
415 s2 = pool_id2solvable(pool, target);
416 POOL_DEBUG(SAT_DEBUG_RESULT, "cannot install both %s and %s\n", solvable2str(pool, s), solvable2str(pool, s2));
418 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
419 s = pool_id2solvable(pool, source);
420 s2 = pool_id2solvable(pool, target);
421 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
423 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
424 s = pool_id2solvable(pool, source);
425 s2 = pool_id2solvable(pool, target);
426 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
428 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
429 s = pool_id2solvable(pool, source);
430 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s requires %s, but none of the providers can be installed\n", solvable2str(pool, s), dep2str(pool, dep));
432 case SOLVER_PROBLEM_SELF_CONFLICT:
433 s = pool_id2solvable(pool, source);
434 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by itself\n", solvable2str(pool, s), dep2str(pool, dep));
440 solver_printsolutions(Solver *solv, Queue *job)
442 Pool *pool = solv->pool;
444 Id p, rp, how, what, select;
445 Id problem, solution, element;
448 POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
451 while ((problem = solver_next_problem(solv, problem)) != 0)
453 POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt++);
454 POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
455 solver_printprobleminfo(solv, job, problem);
456 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
458 while ((solution = solver_next_solution(solv, problem, solution)) != 0)
461 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
465 /* job, rp is index into job queue */
466 how = job->elements[rp - 1] & ~SOLVER_WEAK;
467 what = job->elements[rp];
468 select = how & SOLVER_SELECTMASK;
469 switch (how & SOLVER_JOBMASK)
472 if (select == SOLVER_SOLVABLE && solv->installed && pool->solvables[what].repo == solv->installed)
473 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s installed\n", solvable2str(pool, pool->solvables + what));
474 else if (select == SOLVER_SOLVABLE_PROVIDES)
475 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a solvable %s\n", solver_select2str(solv, select, what));
477 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", solver_select2str(solv, select, what));
480 if (select == SOLVER_SOLVABLE && !(solv->installed && pool->solvables[what].repo == solv->installed))
481 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid installation of %s\n", solvable2str(pool, pool->solvables + what));
482 else if (select == SOLVER_SOLVABLE_PROVIDES)
483 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all solvables %s\n", solver_select2str(solv, select, what));
485 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", solver_select2str(solv, select, what));
488 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most recent version of %s\n", solver_select2str(solv, select, what));
491 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not lock %s\n", solver_select2str(solv, select, what));
494 POOL_DEBUG(SAT_DEBUG_RESULT, "- do something different\n");
500 /* policy, replace p with rp */
501 s = pool->solvables + p;
502 sd = rp ? pool->solvables + rp : 0;
503 if (s == sd && solv->distupgrade)
505 POOL_DEBUG(SAT_DEBUG_RESULT, "- keep obsolete %s\n", solvable2str(pool, s));
510 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr, EVRCMP_MATCH_RELEASE) > 0)
512 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
515 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(solv, s, sd))
517 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
520 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(solv, s, sd))
523 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow vendor change from '%s' (%s) to '%s' (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s), id2str(pool, sd->vendor), solvable2str(pool, sd));
525 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow vendor change from '%s' (%s) to no vendor (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s), solvable2str(pool, sd));
529 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
533 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of %s\n", solvable2str(pool, s));
538 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
544 solver_printtrivial(Solver *solv)
546 Pool *pool = solv->pool;
555 for (p = 1, s = pool->solvables + p; p < solv->pool->nsolvables; p++, s++)
557 n = id2str(pool, s->name);
558 if (strncmp(n, "patch:", 6) != 0 && strncmp(n, "pattern:", 8) != 0)
567 solver_create_state_maps(solv, &installedmap, 0);
569 pool_trivial_installable(pool, solv->installed, &installedmap, &in, &out);
570 POOL_DEBUG(SAT_DEBUG_RESULT, "trivial installable status:\n");
571 for (i = 0; i < in.count; i++)
572 POOL_DEBUG(SAT_DEBUG_RESULT, " %s: %d\n", solvable2str(pool, pool->solvables + in.elements[i]), out.elements[i]);
573 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
574 map_free(&installedmap);
580 solver_select2str(Solver *solv, Id select, Id what)
582 Pool *pool = solv->pool;
585 if (select == SOLVER_SOLVABLE)
586 return solvable2str(pool, pool->solvables + what);
587 if (select == SOLVER_SOLVABLE_NAME)
588 return dep2str(pool, what);
589 if (select == SOLVER_SOLVABLE_PROVIDES)
591 s = dep2str(pool, what);
592 b = pool_alloctmpspace(pool, 11 + strlen(s));
593 sprintf(b, "providing %s", s);
596 if (select == SOLVER_SOLVABLE_ONE_OF)
601 while ((p = pool->whatprovidesdata[what++]) != 0)
603 s = solvable2str(pool, pool->solvables + p);
604 b2 = pool_alloctmpspace(pool, strlen(b) + strlen(s) + 3);
605 sprintf(b2, "%s, %s", b, s);
608 return *b ? b + 2 : "nothing";
610 return "unknown job select";