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->infarchrules && p < solv->infarchrules_end)
199 POOL_DEBUG(type, "INFARCH ");
200 else if (p >= solv->duprules && p < solv->duprules_end)
201 POOL_DEBUG(type, "DUP ");
202 else if (p >= solv->jobrules && p < solv->jobrules_end)
203 POOL_DEBUG(type, "JOB ");
204 else if (p >= solv->updaterules && p < solv->updaterules_end)
205 POOL_DEBUG(type, "UPDATE ");
206 else if (p >= solv->featurerules && p < solv->featurerules_end)
207 POOL_DEBUG(type, "FEATURE ");
208 solver_printrule(solv, type, r);
212 solver_printproblem(Solver *solv, Id v)
214 Pool *pool = solv->pool;
220 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, solv->rules + v);
224 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "JOB %d\n", v);
225 jp = solv->ruletojob.elements;
226 for (i = solv->jobrules, r = solv->rules + i; i < solv->learntrules; i++, r++, jp++)
229 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "- ");
230 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
232 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "ENDJOB\n");
237 solver_printwatches(Solver *solv, int type)
239 Pool *pool = solv->pool;
242 POOL_DEBUG(type, "Watches: \n");
243 for (counter = -(pool->nsolvables - 1); counter < pool->nsolvables; counter++)
244 POOL_DEBUG(type, " solvable [%d] -- rule [%d]\n", counter, solv->watches[counter + pool->nsolvables]);
252 solver_printdecisions(Solver *solv)
254 Pool *pool = solv->pool;
255 Repo *installed = solv->installed;
256 Id p, *obsoletesmap = solver_create_decisions_obsoletesmap(solv);
260 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
262 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n");
263 for (i = 0; i < solv->decisionq.count; i++)
265 p = solv->decisionq.elements[i];
266 solver_printruleelement(solv, SAT_DEBUG_SCHUBI, 0, p);
268 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n");
271 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
272 POOL_DEBUG(SAT_DEBUG_RESULT, "transaction:\n");
274 /* print solvables to be erased */
278 FOR_REPO_SOLVABLES(installed, p, s)
280 if (solv->decisionmap[p] > 0)
284 POOL_DEBUG(SAT_DEBUG_RESULT, " erase %s\n", solvable2str(pool, s));
288 /* print solvables to be installed */
290 for (i = 0; i < solv->decisionq.count; i++)
293 p = solv->decisionq.elements[i];
296 if (p == SYSTEMSOLVABLE)
298 s = pool->solvables + p;
299 if (installed && s->repo == installed)
302 if (!obsoletesmap[p])
304 POOL_DEBUG(SAT_DEBUG_RESULT, " install %s", solvable2str(pool, s));
309 FOR_PROVIDES(xp, xpp, s->name)
311 Solvable *s2 = pool->solvables + xp;
312 if (s2->name != s->name)
314 if (evrcmp(pool, s->evr, s2->evr, EVRCMP_MATCH_RELEASE) < 0)
318 POOL_DEBUG(SAT_DEBUG_RESULT, " downgrade %s", solvable2str(pool, s));
320 POOL_DEBUG(SAT_DEBUG_RESULT, " upgrade %s", solvable2str(pool, s));
321 POOL_DEBUG(SAT_DEBUG_RESULT, " (obsoletes");
322 for (j = installed->start; j < installed->end; j++)
323 if (obsoletesmap[j] == p)
324 POOL_DEBUG(SAT_DEBUG_RESULT, " %s", solvable2str(pool, pool->solvables + j));
325 POOL_DEBUG(SAT_DEBUG_RESULT, ")");
327 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
329 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
331 sat_free(obsoletesmap);
333 if (solv->recommendations.count)
335 POOL_DEBUG(SAT_DEBUG_RESULT, "recommended packages:\n");
336 for (i = 0; i < solv->recommendations.count; i++)
338 s = pool->solvables + solv->recommendations.elements[i];
339 if (solv->decisionmap[solv->recommendations.elements[i]] > 0)
341 if (installed && s->repo == installed)
342 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (installed)\n", solvable2str(pool, s));
344 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (selected)\n", solvable2str(pool, s));
347 POOL_DEBUG(SAT_DEBUG_RESULT, " %s\n", solvable2str(pool, s));
349 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
352 if (solv->suggestions.count)
354 POOL_DEBUG(SAT_DEBUG_RESULT, "suggested packages:\n");
355 for (i = 0; i < solv->suggestions.count; i++)
357 s = pool->solvables + solv->suggestions.elements[i];
358 if (solv->decisionmap[solv->suggestions.elements[i]] > 0)
360 if (installed && s->repo == installed)
361 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (installed)\n", solvable2str(pool, s));
363 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (selected)\n", solvable2str(pool, s));
366 POOL_DEBUG(SAT_DEBUG_RESULT, " %s\n", solvable2str(pool, s));
368 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
370 if (solv->orphaned.count)
372 POOL_DEBUG(SAT_DEBUG_RESULT, "orphaned packages:\n");
373 for (i = 0; i < solv->orphaned.count; i++)
375 s = pool->solvables + solv->orphaned.elements[i];
376 if (solv->decisionmap[solv->orphaned.elements[i]] > 0)
377 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (kept)\n", solvable2str(pool, s));
379 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (erased)\n", solvable2str(pool, s));
381 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
386 solver_printprobleminfo(Solver *solv, Queue *job, Id problem)
388 Pool *pool = solv->pool;
390 Id dep, source, target;
393 probr = solver_findproblemrule(solv, problem);
394 switch (solver_problemruleinfo(solv, job, probr, &dep, &source, &target))
396 case SOLVER_PROBLEM_DISTUPGRADE_RULE:
397 s = pool_id2solvable(pool, source);
398 POOL_DEBUG(SAT_DEBUG_RESULT, "%s does not belong to a distupgrade repository\n", solvable2str(pool, s));
400 case SOLVER_PROBLEM_INFARCH_RULE:
401 s = pool_id2solvable(pool, source);
402 POOL_DEBUG(SAT_DEBUG_RESULT, "%s has inferior architecture\n", solvable2str(pool, s));
404 case SOLVER_PROBLEM_UPDATE_RULE:
405 s = pool_id2solvable(pool, source);
406 POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", solvable2str(pool, s));
408 case SOLVER_PROBLEM_JOB_RULE:
409 POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n");
411 case SOLVER_PROBLEM_RPM_RULE:
412 POOL_DEBUG(SAT_DEBUG_RESULT, "some dependency problem\n");
414 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
415 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep));
417 case SOLVER_PROBLEM_NOT_INSTALLABLE:
418 s = pool_id2solvable(pool, source);
419 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s is not installable\n", solvable2str(pool, s));
421 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
422 s = pool_id2solvable(pool, source);
423 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides %s needed by %s\n", dep2str(pool, dep), solvable2str(pool, s));
425 case SOLVER_PROBLEM_SAME_NAME:
426 s = pool_id2solvable(pool, source);
427 s2 = pool_id2solvable(pool, target);
428 POOL_DEBUG(SAT_DEBUG_RESULT, "cannot install both %s and %s\n", solvable2str(pool, s), solvable2str(pool, s2));
430 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
431 s = pool_id2solvable(pool, source);
432 s2 = pool_id2solvable(pool, target);
433 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
435 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
436 s = pool_id2solvable(pool, source);
437 s2 = pool_id2solvable(pool, target);
438 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
440 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
441 s = pool_id2solvable(pool, source);
442 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s requires %s, but none of the providers can be installed\n", solvable2str(pool, s), dep2str(pool, dep));
444 case SOLVER_PROBLEM_SELF_CONFLICT:
445 s = pool_id2solvable(pool, source);
446 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by itself\n", solvable2str(pool, s), dep2str(pool, dep));
452 solver_printsolutions(Solver *solv, Queue *job)
454 Pool *pool = solv->pool;
456 Id p, rp, how, what, select;
457 Id problem, solution, element;
460 POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
463 while ((problem = solver_next_problem(solv, problem)) != 0)
465 POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt++);
466 POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
467 solver_printprobleminfo(solv, job, problem);
468 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
470 while ((solution = solver_next_solution(solv, problem, solution)) != 0)
473 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
475 if (p == SOLVER_SOLUTION_JOB)
477 /* job, rp is index into job queue */
478 how = job->elements[rp - 1];
479 what = job->elements[rp];
480 select = how & SOLVER_SELECTMASK;
481 switch (how & SOLVER_JOBMASK)
484 if (select == SOLVER_SOLVABLE && solv->installed && pool->solvables[what].repo == solv->installed)
485 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s installed\n", solvable2str(pool, pool->solvables + what));
486 else if (select == SOLVER_SOLVABLE_PROVIDES)
487 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a solvable %s\n", solver_select2str(solv, select, what));
489 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", solver_select2str(solv, select, what));
492 if (select == SOLVER_SOLVABLE && !(solv->installed && pool->solvables[what].repo == solv->installed))
493 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid installation of %s\n", solvable2str(pool, pool->solvables + what));
494 else if (select == SOLVER_SOLVABLE_PROVIDES)
495 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all solvables %s\n", solver_select2str(solv, select, what));
497 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", solver_select2str(solv, select, what));
500 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most recent version of %s\n", solver_select2str(solv, select, what));
503 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not lock %s\n", solver_select2str(solv, select, what));
506 POOL_DEBUG(SAT_DEBUG_RESULT, "- do something different\n");
510 else if (p == SOLVER_SOLUTION_INFARCH)
512 s = pool->solvables + rp;
513 if (solv->installed && s->repo == solv->installed)
514 POOL_DEBUG(SAT_DEBUG_RESULT, "- keep %s despite the inferior architecture\n", solvable2str(pool, s));
516 POOL_DEBUG(SAT_DEBUG_RESULT, "- install %s despite the inferior architecture\n", solvable2str(pool, s));
518 else if (p == SOLVER_SOLUTION_DISTUPGRADE)
520 s = pool->solvables + rp;
521 if (solv->installed && s->repo == solv->installed)
522 POOL_DEBUG(SAT_DEBUG_RESULT, "- keep obsolete %s\n", solvable2str(pool, s));
524 POOL_DEBUG(SAT_DEBUG_RESULT, "- install %s from excluded repository\n", solvable2str(pool, s));
528 /* policy, replace p with rp */
529 s = pool->solvables + p;
530 sd = rp ? pool->solvables + rp : 0;
531 if (s == sd && solv->distupgrade)
533 POOL_DEBUG(SAT_DEBUG_RESULT, "- keep obsolete %s\n", solvable2str(pool, s));
538 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr, EVRCMP_MATCH_RELEASE) > 0)
540 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
543 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(solv, s, sd))
545 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
548 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(solv, s, sd))
551 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));
553 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));
557 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
561 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of %s\n", solvable2str(pool, s));
566 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
572 solver_printtrivial(Solver *solv)
574 Pool *pool = solv->pool;
583 for (p = 1, s = pool->solvables + p; p < solv->pool->nsolvables; p++, s++)
585 n = id2str(pool, s->name);
586 if (strncmp(n, "patch:", 6) != 0 && strncmp(n, "pattern:", 8) != 0)
595 solver_create_state_maps(solv, &installedmap, 0);
597 pool_trivial_installable(pool, &installedmap, &in, &out);
598 POOL_DEBUG(SAT_DEBUG_RESULT, "trivial installable status:\n");
599 for (i = 0; i < in.count; i++)
600 POOL_DEBUG(SAT_DEBUG_RESULT, " %s: %d\n", solvable2str(pool, pool->solvables + in.elements[i]), out.elements[i]);
601 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
602 map_free(&installedmap);
608 solver_select2str(Solver *solv, Id select, Id what)
610 Pool *pool = solv->pool;
613 if (select == SOLVER_SOLVABLE)
614 return solvable2str(pool, pool->solvables + what);
615 if (select == SOLVER_SOLVABLE_NAME)
616 return dep2str(pool, what);
617 if (select == SOLVER_SOLVABLE_PROVIDES)
619 s = dep2str(pool, what);
620 b = pool_alloctmpspace(pool, 11 + strlen(s));
621 sprintf(b, "providing %s", s);
624 if (select == SOLVER_SOLVABLE_ONE_OF)
629 while ((p = pool->whatprovidesdata[what++]) != 0)
631 s = solvable2str(pool, pool->solvables + p);
632 b2 = pool_alloctmpspace(pool, strlen(b) + strlen(s) + 3);
633 sprintf(b2, "%s, %s", b, s);
636 return *b ? b + 2 : "nothing";
638 return "unknown job select";